1960366cfSKarsten Keil /*
2960366cfSKarsten Keil * Audio crossconnecting/conferrencing (hardware level).
3960366cfSKarsten Keil *
4960366cfSKarsten Keil * Copyright 2002 by Andreas Eversberg (jolly@eversberg.eu)
5960366cfSKarsten Keil *
6960366cfSKarsten Keil * This software may be used and distributed according to the terms
7960366cfSKarsten Keil * of the GNU General Public License, incorporated herein by reference.
8960366cfSKarsten Keil *
9960366cfSKarsten Keil */
10960366cfSKarsten Keil
11960366cfSKarsten Keil /*
12960366cfSKarsten Keil * The process of adding and removing parties to/from a conference:
13960366cfSKarsten Keil *
14960366cfSKarsten Keil * There is a chain of struct dsp_conf which has one or more members in a chain
15960366cfSKarsten Keil * of struct dsp_conf_member.
16960366cfSKarsten Keil *
17960366cfSKarsten Keil * After a party is added, the conference is checked for hardware capability.
18960366cfSKarsten Keil * Also if a party is removed, the conference is checked again.
19960366cfSKarsten Keil *
20960366cfSKarsten Keil * There are 3 different solutions: -1 = software, 0 = hardware-crossconnect
21960366cfSKarsten Keil * 1-n = hardware-conference. The n will give the conference number.
22960366cfSKarsten Keil *
23960366cfSKarsten Keil * Depending on the change after removal or insertion of a party, hardware
24960366cfSKarsten Keil * commands are given.
25960366cfSKarsten Keil *
26960366cfSKarsten Keil * The current solution is stored within the struct dsp_conf entry.
27960366cfSKarsten Keil */
28960366cfSKarsten Keil
29960366cfSKarsten Keil /*
30960366cfSKarsten Keil * HOW THE CMX WORKS:
31960366cfSKarsten Keil *
32960366cfSKarsten Keil * There are 3 types of interaction: One member is alone, in this case only
33960366cfSKarsten Keil * data flow from upper to lower layer is done.
34960366cfSKarsten Keil * Two members will also exchange their data so they are crossconnected.
35960366cfSKarsten Keil * Three or more members will be added in a conference and will hear each
36960366cfSKarsten Keil * other but will not receive their own speech (echo) if not enabled.
37960366cfSKarsten Keil *
38960366cfSKarsten Keil * Features of CMX are:
39960366cfSKarsten Keil * - Crossconnecting or even conference, if more than two members are together.
40960366cfSKarsten Keil * - Force mixing of transmit data with other crossconnect/conference members.
41960366cfSKarsten Keil * - Echo generation to benchmark the delay of audio processing.
42960366cfSKarsten Keil * - Use hardware to minimize cpu load, disable FIFO load and minimize delay.
43960366cfSKarsten Keil * - Dejittering and clock generation.
44960366cfSKarsten Keil *
45960366cfSKarsten Keil * There are 2 buffers:
46960366cfSKarsten Keil *
47960366cfSKarsten Keil *
48960366cfSKarsten Keil * RX-Buffer
49960366cfSKarsten Keil * R W
50960366cfSKarsten Keil * | |
51960366cfSKarsten Keil * ----------------+-------------+-------------------
52960366cfSKarsten Keil *
53960366cfSKarsten Keil * The rx-buffer is a ring buffer used to store the received data for each
54960366cfSKarsten Keil * individual member. This is only the case if data needs to be dejittered
55960366cfSKarsten Keil * or in case of a conference where different clocks require reclocking.
56960366cfSKarsten Keil * The transmit-clock (R) will read the buffer.
57960366cfSKarsten Keil * If the clock overruns the write-pointer, we will have a buffer underrun.
58960366cfSKarsten Keil * If the write pointer always has a certain distance from the transmit-
59960366cfSKarsten Keil * clock, we will have a delay. The delay will dynamically be increased and
60960366cfSKarsten Keil * reduced.
61960366cfSKarsten Keil *
62960366cfSKarsten Keil *
63960366cfSKarsten Keil * TX-Buffer
64960366cfSKarsten Keil * R W
65960366cfSKarsten Keil * | |
66960366cfSKarsten Keil * -----------------+--------+-----------------------
67960366cfSKarsten Keil *
68960366cfSKarsten Keil * The tx-buffer is a ring buffer to queue the transmit data from user space
69960366cfSKarsten Keil * until it will be mixed or sent. There are two pointers, R and W. If the write
70960366cfSKarsten Keil * pointer W would reach or overrun R, the buffer would overrun. In this case
71960366cfSKarsten Keil * (some) data is dropped so that it will not overrun.
72960366cfSKarsten Keil * Additionally a dynamic dejittering can be enabled. this allows data from
73960366cfSKarsten Keil * user space that have jitter and different clock source.
74960366cfSKarsten Keil *
75960366cfSKarsten Keil *
76960366cfSKarsten Keil * Clock:
77960366cfSKarsten Keil *
78960366cfSKarsten Keil * A Clock is not required, if the data source has exactly one clock. In this
79960366cfSKarsten Keil * case the data source is forwarded to the destination.
80960366cfSKarsten Keil *
81960366cfSKarsten Keil * A Clock is required, because the data source
82960366cfSKarsten Keil * - has multiple clocks.
83960366cfSKarsten Keil * - has no usable clock due to jitter or packet loss (VoIP).
84960366cfSKarsten Keil * In this case the system's clock is used. The clock resolution depends on
85*bd7c8ff9SAnna-Maria Behnsen * the jiffy resolution.
86960366cfSKarsten Keil *
87960366cfSKarsten Keil * If a member joins a conference:
88960366cfSKarsten Keil *
89960366cfSKarsten Keil * - If a member joins, its rx_buff is set to silence and change read pointer
90960366cfSKarsten Keil * to transmit clock.
91960366cfSKarsten Keil *
92960366cfSKarsten Keil * The procedure of received data from card is explained in cmx_receive.
93960366cfSKarsten Keil * The procedure of received data from user space is explained in cmx_transmit.
94960366cfSKarsten Keil * The procedure of transmit data to card is cmx_send.
95960366cfSKarsten Keil *
96960366cfSKarsten Keil *
97960366cfSKarsten Keil * Interaction with other features:
98960366cfSKarsten Keil *
99960366cfSKarsten Keil * DTMF:
100960366cfSKarsten Keil * DTMF decoding is done before the data is crossconnected.
101960366cfSKarsten Keil *
102960366cfSKarsten Keil * Volume change:
103960366cfSKarsten Keil * Changing rx-volume is done before the data is crossconnected. The tx-volume
104960366cfSKarsten Keil * must be changed whenever data is transmitted to the card by the cmx.
105960366cfSKarsten Keil *
106960366cfSKarsten Keil * Tones:
107960366cfSKarsten Keil * If a tone is enabled, it will be processed whenever data is transmitted to
108960366cfSKarsten Keil * the card. It will replace the tx-data from the user space.
109960366cfSKarsten Keil * If tones are generated by hardware, this conference member is removed for
110960366cfSKarsten Keil * this time.
111960366cfSKarsten Keil *
112960366cfSKarsten Keil * Disable rx-data:
113960366cfSKarsten Keil * If cmx is realized in hardware, rx data will be disabled if requested by
114960366cfSKarsten Keil * the upper layer. If dtmf decoding is done by software and enabled, rx data
11548e34d0fSJustin P. Mattock * will not be disabled but blocked to the upper layer.
116960366cfSKarsten Keil *
117960366cfSKarsten Keil * HFC conference engine:
118960366cfSKarsten Keil * If it is possible to realize all features using hardware, hardware will be
119960366cfSKarsten Keil * used if not forbidden by control command. Disabling rx-data provides
120960366cfSKarsten Keil * absolutely traffic free audio processing. (except for the quick 1-frame
121960366cfSKarsten Keil * upload of a tone loop, only once for a new tone)
122960366cfSKarsten Keil *
123960366cfSKarsten Keil */
124960366cfSKarsten Keil
125960366cfSKarsten Keil /* delay.h is required for hw_lock.h */
126960366cfSKarsten Keil
1275a0e3ad6STejun Heo #include <linux/slab.h>
128960366cfSKarsten Keil #include <linux/delay.h>
129960366cfSKarsten Keil #include <linux/mISDNif.h>
130960366cfSKarsten Keil #include <linux/mISDNdsp.h>
131960366cfSKarsten Keil #include "core.h"
132960366cfSKarsten Keil #include "dsp.h"
133960366cfSKarsten Keil /*
134960366cfSKarsten Keil * debugging of multi party conference,
135960366cfSKarsten Keil * by using conference even with two members
136960366cfSKarsten Keil */
137960366cfSKarsten Keil
138960366cfSKarsten Keil /* #define CMX_CONF_DEBUG */
139960366cfSKarsten Keil
140960366cfSKarsten Keil /*#define CMX_DEBUG * massive read/write pointer output */
14187c5fa1bSAndreas Eversberg /*#define CMX_DELAY_DEBUG * gives rx-buffer delay overview */
142960366cfSKarsten Keil /*#define CMX_TX_DEBUG * massive read/write on tx-buffer with content */
143960366cfSKarsten Keil
144960366cfSKarsten Keil /*
145960366cfSKarsten Keil * debug cmx memory structure
146960366cfSKarsten Keil */
147960366cfSKarsten Keil void
dsp_cmx_debug(struct dsp * dsp)148960366cfSKarsten Keil dsp_cmx_debug(struct dsp *dsp)
149960366cfSKarsten Keil {
150960366cfSKarsten Keil struct dsp_conf *conf;
151960366cfSKarsten Keil struct dsp_conf_member *member;
152960366cfSKarsten Keil struct dsp *odsp;
153960366cfSKarsten Keil
154960366cfSKarsten Keil printk(KERN_DEBUG "-----Current DSP\n");
155960366cfSKarsten Keil list_for_each_entry(odsp, &dsp_ilist, list) {
156bc138ec4SAndreas Eversberg printk(KERN_DEBUG "* %s hardecho=%d softecho=%d txmix=%d",
157bc138ec4SAndreas Eversberg odsp->name, odsp->echo.hardware, odsp->echo.software,
158bc138ec4SAndreas Eversberg odsp->tx_mix);
159960366cfSKarsten Keil if (odsp->conf)
160960366cfSKarsten Keil printk(" (Conf %d)", odsp->conf->id);
161960366cfSKarsten Keil if (dsp == odsp)
162960366cfSKarsten Keil printk(" *this*");
163960366cfSKarsten Keil printk("\n");
164960366cfSKarsten Keil }
165960366cfSKarsten Keil printk(KERN_DEBUG "-----Current Conf:\n");
166960366cfSKarsten Keil list_for_each_entry(conf, &conf_ilist, list) {
167960366cfSKarsten Keil printk(KERN_DEBUG "* Conf %d (%p)\n", conf->id, conf);
168960366cfSKarsten Keil list_for_each_entry(member, &conf->mlist, list) {
169960366cfSKarsten Keil printk(KERN_DEBUG
170960366cfSKarsten Keil " - member = %s (slot_tx %d, bank_tx %d, "
171bc138ec4SAndreas Eversberg "slot_rx %d, bank_rx %d hfc_conf %d "
172bc138ec4SAndreas Eversberg "tx_data %d rx_is_off %d)%s\n",
173960366cfSKarsten Keil member->dsp->name, member->dsp->pcm_slot_tx,
174960366cfSKarsten Keil member->dsp->pcm_bank_tx, member->dsp->pcm_slot_rx,
175960366cfSKarsten Keil member->dsp->pcm_bank_rx, member->dsp->hfc_conf,
176bc138ec4SAndreas Eversberg member->dsp->tx_data, member->dsp->rx_is_off,
177960366cfSKarsten Keil (member->dsp == dsp) ? " *this*" : "");
178960366cfSKarsten Keil }
179960366cfSKarsten Keil }
180960366cfSKarsten Keil printk(KERN_DEBUG "-----end\n");
181960366cfSKarsten Keil }
182960366cfSKarsten Keil
183960366cfSKarsten Keil /*
184960366cfSKarsten Keil * search conference
185960366cfSKarsten Keil */
186960366cfSKarsten Keil static struct dsp_conf *
dsp_cmx_search_conf(u32 id)187960366cfSKarsten Keil dsp_cmx_search_conf(u32 id)
188960366cfSKarsten Keil {
189960366cfSKarsten Keil struct dsp_conf *conf;
190960366cfSKarsten Keil
191960366cfSKarsten Keil if (!id) {
192960366cfSKarsten Keil printk(KERN_WARNING "%s: conference ID is 0.\n", __func__);
193960366cfSKarsten Keil return NULL;
194960366cfSKarsten Keil }
195960366cfSKarsten Keil
196960366cfSKarsten Keil /* search conference */
197960366cfSKarsten Keil list_for_each_entry(conf, &conf_ilist, list)
198960366cfSKarsten Keil if (conf->id == id)
199960366cfSKarsten Keil return conf;
200960366cfSKarsten Keil
201960366cfSKarsten Keil return NULL;
202960366cfSKarsten Keil }
203960366cfSKarsten Keil
204960366cfSKarsten Keil
205960366cfSKarsten Keil /*
206960366cfSKarsten Keil * add member to conference
207960366cfSKarsten Keil */
208960366cfSKarsten Keil static int
dsp_cmx_add_conf_member(struct dsp * dsp,struct dsp_conf * conf)209960366cfSKarsten Keil dsp_cmx_add_conf_member(struct dsp *dsp, struct dsp_conf *conf)
210960366cfSKarsten Keil {
211960366cfSKarsten Keil struct dsp_conf_member *member;
212960366cfSKarsten Keil
213960366cfSKarsten Keil if (!conf || !dsp) {
214960366cfSKarsten Keil printk(KERN_WARNING "%s: conf or dsp is 0.\n", __func__);
215960366cfSKarsten Keil return -EINVAL;
216960366cfSKarsten Keil }
217960366cfSKarsten Keil if (dsp->member) {
218960366cfSKarsten Keil printk(KERN_WARNING "%s: dsp is already member in a conf.\n",
219960366cfSKarsten Keil __func__);
220960366cfSKarsten Keil return -EINVAL;
221960366cfSKarsten Keil }
222960366cfSKarsten Keil
223960366cfSKarsten Keil if (dsp->conf) {
224960366cfSKarsten Keil printk(KERN_WARNING "%s: dsp is already in a conf.\n",
225960366cfSKarsten Keil __func__);
226960366cfSKarsten Keil return -EINVAL;
227960366cfSKarsten Keil }
228960366cfSKarsten Keil
229960366cfSKarsten Keil member = kzalloc(sizeof(struct dsp_conf_member), GFP_ATOMIC);
230960366cfSKarsten Keil if (!member) {
231eac74af9SKarsten Keil printk(KERN_ERR "kzalloc struct dsp_conf_member failed\n");
232960366cfSKarsten Keil return -ENOMEM;
233960366cfSKarsten Keil }
234960366cfSKarsten Keil member->dsp = dsp;
235960366cfSKarsten Keil /* clear rx buffer */
236960366cfSKarsten Keil memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff));
237960366cfSKarsten Keil dsp->rx_init = 1; /* rx_W and rx_R will be adjusted on first frame */
238960366cfSKarsten Keil dsp->rx_W = 0;
239960366cfSKarsten Keil dsp->rx_R = 0;
240960366cfSKarsten Keil
241960366cfSKarsten Keil list_add_tail(&member->list, &conf->mlist);
242960366cfSKarsten Keil
243960366cfSKarsten Keil dsp->conf = conf;
244960366cfSKarsten Keil dsp->member = member;
245960366cfSKarsten Keil
246960366cfSKarsten Keil return 0;
247960366cfSKarsten Keil }
248960366cfSKarsten Keil
249960366cfSKarsten Keil
250960366cfSKarsten Keil /*
251960366cfSKarsten Keil * del member from conference
252960366cfSKarsten Keil */
253960366cfSKarsten Keil int
dsp_cmx_del_conf_member(struct dsp * dsp)254960366cfSKarsten Keil dsp_cmx_del_conf_member(struct dsp *dsp)
255960366cfSKarsten Keil {
256960366cfSKarsten Keil struct dsp_conf_member *member;
257960366cfSKarsten Keil
258960366cfSKarsten Keil if (!dsp) {
259960366cfSKarsten Keil printk(KERN_WARNING "%s: dsp is 0.\n",
260960366cfSKarsten Keil __func__);
261960366cfSKarsten Keil return -EINVAL;
262960366cfSKarsten Keil }
263960366cfSKarsten Keil
264960366cfSKarsten Keil if (!dsp->conf) {
265960366cfSKarsten Keil printk(KERN_WARNING "%s: dsp is not in a conf.\n",
266960366cfSKarsten Keil __func__);
267960366cfSKarsten Keil return -EINVAL;
268960366cfSKarsten Keil }
269960366cfSKarsten Keil
270960366cfSKarsten Keil if (list_empty(&dsp->conf->mlist)) {
271960366cfSKarsten Keil printk(KERN_WARNING "%s: dsp has linked an empty conf.\n",
272960366cfSKarsten Keil __func__);
273960366cfSKarsten Keil return -EINVAL;
274960366cfSKarsten Keil }
275960366cfSKarsten Keil
276960366cfSKarsten Keil /* find us in conf */
277960366cfSKarsten Keil list_for_each_entry(member, &dsp->conf->mlist, list) {
278960366cfSKarsten Keil if (member->dsp == dsp) {
279960366cfSKarsten Keil list_del(&member->list);
280960366cfSKarsten Keil dsp->conf = NULL;
281960366cfSKarsten Keil dsp->member = NULL;
282960366cfSKarsten Keil kfree(member);
283960366cfSKarsten Keil return 0;
284960366cfSKarsten Keil }
285960366cfSKarsten Keil }
286960366cfSKarsten Keil printk(KERN_WARNING
287d939be3aSMasanari Iida "%s: dsp is not present in its own conf_member list.\n",
288960366cfSKarsten Keil __func__);
289960366cfSKarsten Keil
290960366cfSKarsten Keil return -EINVAL;
291960366cfSKarsten Keil }
292960366cfSKarsten Keil
293960366cfSKarsten Keil
294960366cfSKarsten Keil /*
295960366cfSKarsten Keil * new conference
296960366cfSKarsten Keil */
297960366cfSKarsten Keil static struct dsp_conf
dsp_cmx_new_conf(u32 id)298960366cfSKarsten Keil *dsp_cmx_new_conf(u32 id)
299960366cfSKarsten Keil {
300960366cfSKarsten Keil struct dsp_conf *conf;
301960366cfSKarsten Keil
302960366cfSKarsten Keil if (!id) {
303960366cfSKarsten Keil printk(KERN_WARNING "%s: id is 0.\n",
304960366cfSKarsten Keil __func__);
305960366cfSKarsten Keil return NULL;
306960366cfSKarsten Keil }
307960366cfSKarsten Keil
308960366cfSKarsten Keil conf = kzalloc(sizeof(struct dsp_conf), GFP_ATOMIC);
309960366cfSKarsten Keil if (!conf) {
310eac74af9SKarsten Keil printk(KERN_ERR "kzalloc struct dsp_conf failed\n");
311960366cfSKarsten Keil return NULL;
312960366cfSKarsten Keil }
313960366cfSKarsten Keil INIT_LIST_HEAD(&conf->mlist);
314960366cfSKarsten Keil conf->id = id;
315960366cfSKarsten Keil
316960366cfSKarsten Keil list_add_tail(&conf->list, &conf_ilist);
317960366cfSKarsten Keil
318960366cfSKarsten Keil return conf;
319960366cfSKarsten Keil }
320960366cfSKarsten Keil
321960366cfSKarsten Keil
322960366cfSKarsten Keil /*
323960366cfSKarsten Keil * del conference
324960366cfSKarsten Keil */
325960366cfSKarsten Keil int
dsp_cmx_del_conf(struct dsp_conf * conf)326960366cfSKarsten Keil dsp_cmx_del_conf(struct dsp_conf *conf)
327960366cfSKarsten Keil {
328960366cfSKarsten Keil if (!conf) {
329960366cfSKarsten Keil printk(KERN_WARNING "%s: conf is null.\n",
330960366cfSKarsten Keil __func__);
331960366cfSKarsten Keil return -EINVAL;
332960366cfSKarsten Keil }
333960366cfSKarsten Keil
334960366cfSKarsten Keil if (!list_empty(&conf->mlist)) {
335960366cfSKarsten Keil printk(KERN_WARNING "%s: conf not empty.\n",
336960366cfSKarsten Keil __func__);
337960366cfSKarsten Keil return -EINVAL;
338960366cfSKarsten Keil }
339960366cfSKarsten Keil list_del(&conf->list);
340960366cfSKarsten Keil kfree(conf);
341960366cfSKarsten Keil
342960366cfSKarsten Keil return 0;
343960366cfSKarsten Keil }
344960366cfSKarsten Keil
345960366cfSKarsten Keil
346960366cfSKarsten Keil /*
347960366cfSKarsten Keil * send HW message to hfc card
348960366cfSKarsten Keil */
349960366cfSKarsten Keil static void
dsp_cmx_hw_message(struct dsp * dsp,u32 message,u32 param1,u32 param2,u32 param3,u32 param4)350960366cfSKarsten Keil dsp_cmx_hw_message(struct dsp *dsp, u32 message, u32 param1, u32 param2,
351960366cfSKarsten Keil u32 param3, u32 param4)
352960366cfSKarsten Keil {
353960366cfSKarsten Keil struct mISDN_ctrl_req cq;
354960366cfSKarsten Keil
355960366cfSKarsten Keil memset(&cq, 0, sizeof(cq));
356960366cfSKarsten Keil cq.op = message;
357960366cfSKarsten Keil cq.p1 = param1 | (param2 << 8);
358960366cfSKarsten Keil cq.p2 = param3 | (param4 << 8);
359960366cfSKarsten Keil if (dsp->ch.peer)
360960366cfSKarsten Keil dsp->ch.peer->ctrl(dsp->ch.peer, CONTROL_CHANNEL, &cq);
361960366cfSKarsten Keil }
362960366cfSKarsten Keil
363960366cfSKarsten Keil
364960366cfSKarsten Keil /*
365960366cfSKarsten Keil * do hardware update and set the software/hardware flag
366960366cfSKarsten Keil *
367960366cfSKarsten Keil * either a conference or a dsp instance can be given
368960366cfSKarsten Keil * if only dsp instance is given, the instance is not associated with a conf
369960366cfSKarsten Keil * and therefore removed. if a conference is given, the dsp is expected to
370960366cfSKarsten Keil * be member of that conference.
371960366cfSKarsten Keil */
372960366cfSKarsten Keil void
dsp_cmx_hardware(struct dsp_conf * conf,struct dsp * dsp)373960366cfSKarsten Keil dsp_cmx_hardware(struct dsp_conf *conf, struct dsp *dsp)
374960366cfSKarsten Keil {
375960366cfSKarsten Keil struct dsp_conf_member *member, *nextm;
376960366cfSKarsten Keil struct dsp *finddsp;
377960366cfSKarsten Keil int memb = 0, i, ii, i1, i2;
378960366cfSKarsten Keil int freeunits[8];
379960366cfSKarsten Keil u_char freeslots[256];
380960366cfSKarsten Keil int same_hfc = -1, same_pcm = -1, current_conf = -1,
381bc138ec4SAndreas Eversberg all_conf = 1, tx_data = 0;
382960366cfSKarsten Keil
383960366cfSKarsten Keil /* dsp gets updated (no conf) */
384960366cfSKarsten Keil if (!conf) {
385960366cfSKarsten Keil if (!dsp)
386960366cfSKarsten Keil return;
387960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
388960366cfSKarsten Keil printk(KERN_DEBUG "%s checking dsp %s\n",
389960366cfSKarsten Keil __func__, dsp->name);
390960366cfSKarsten Keil one_member:
391960366cfSKarsten Keil /* remove HFC conference if enabled */
392960366cfSKarsten Keil if (dsp->hfc_conf >= 0) {
393960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
394960366cfSKarsten Keil printk(KERN_DEBUG
395960366cfSKarsten Keil "%s removing %s from HFC conf %d "
396960366cfSKarsten Keil "because dsp is split\n", __func__,
397960366cfSKarsten Keil dsp->name, dsp->hfc_conf);
398960366cfSKarsten Keil dsp_cmx_hw_message(dsp, MISDN_CTRL_HFC_CONF_SPLIT,
399960366cfSKarsten Keil 0, 0, 0, 0);
400960366cfSKarsten Keil dsp->hfc_conf = -1;
401960366cfSKarsten Keil }
402960366cfSKarsten Keil /* process hw echo */
403960366cfSKarsten Keil if (dsp->features.pcm_banks < 1)
404960366cfSKarsten Keil return;
405bc138ec4SAndreas Eversberg if (!dsp->echo.software && !dsp->echo.hardware) {
406960366cfSKarsten Keil /* NO ECHO: remove PCM slot if assigned */
407960366cfSKarsten Keil if (dsp->pcm_slot_tx >= 0 || dsp->pcm_slot_rx >= 0) {
408960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
409960366cfSKarsten Keil printk(KERN_DEBUG "%s removing %s from"
410960366cfSKarsten Keil " PCM slot %d (TX) %d (RX) because"
411960366cfSKarsten Keil " dsp is split (no echo)\n",
412960366cfSKarsten Keil __func__, dsp->name,
413960366cfSKarsten Keil dsp->pcm_slot_tx, dsp->pcm_slot_rx);
414960366cfSKarsten Keil dsp_cmx_hw_message(dsp, MISDN_CTRL_HFC_PCM_DISC,
415960366cfSKarsten Keil 0, 0, 0, 0);
416960366cfSKarsten Keil dsp->pcm_slot_tx = -1;
417960366cfSKarsten Keil dsp->pcm_bank_tx = -1;
418960366cfSKarsten Keil dsp->pcm_slot_rx = -1;
419960366cfSKarsten Keil dsp->pcm_bank_rx = -1;
420960366cfSKarsten Keil }
421960366cfSKarsten Keil return;
422960366cfSKarsten Keil }
423bc138ec4SAndreas Eversberg /* echo is enabled, find out if we use soft or hardware */
424bc138ec4SAndreas Eversberg dsp->echo.software = dsp->tx_data;
425bc138ec4SAndreas Eversberg dsp->echo.hardware = 0;
426960366cfSKarsten Keil /* ECHO: already echo */
427960366cfSKarsten Keil if (dsp->pcm_slot_tx >= 0 && dsp->pcm_slot_rx < 0 &&
428bc138ec4SAndreas Eversberg dsp->pcm_bank_tx == 2 && dsp->pcm_bank_rx == 2) {
429bc138ec4SAndreas Eversberg dsp->echo.hardware = 1;
430960366cfSKarsten Keil return;
431bc138ec4SAndreas Eversberg }
432960366cfSKarsten Keil /* ECHO: if slot already assigned */
433960366cfSKarsten Keil if (dsp->pcm_slot_tx >= 0) {
434960366cfSKarsten Keil dsp->pcm_slot_rx = dsp->pcm_slot_tx;
435960366cfSKarsten Keil dsp->pcm_bank_tx = 2; /* 2 means loop */
436960366cfSKarsten Keil dsp->pcm_bank_rx = 2;
437960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
438960366cfSKarsten Keil printk(KERN_DEBUG
439960366cfSKarsten Keil "%s refresh %s for echo using slot %d\n",
440960366cfSKarsten Keil __func__, dsp->name,
441960366cfSKarsten Keil dsp->pcm_slot_tx);
442960366cfSKarsten Keil dsp_cmx_hw_message(dsp, MISDN_CTRL_HFC_PCM_CONN,
443960366cfSKarsten Keil dsp->pcm_slot_tx, 2, dsp->pcm_slot_rx, 2);
444bc138ec4SAndreas Eversberg dsp->echo.hardware = 1;
445960366cfSKarsten Keil return;
446960366cfSKarsten Keil }
447960366cfSKarsten Keil /* ECHO: find slot */
448960366cfSKarsten Keil dsp->pcm_slot_tx = -1;
449960366cfSKarsten Keil dsp->pcm_slot_rx = -1;
450960366cfSKarsten Keil memset(freeslots, 1, sizeof(freeslots));
451960366cfSKarsten Keil list_for_each_entry(finddsp, &dsp_ilist, list) {
452960366cfSKarsten Keil if (finddsp->features.pcm_id == dsp->features.pcm_id) {
453960366cfSKarsten Keil if (finddsp->pcm_slot_rx >= 0 &&
454960366cfSKarsten Keil finddsp->pcm_slot_rx < sizeof(freeslots))
4559e9540b8SAdrian Bunk freeslots[finddsp->pcm_slot_rx] = 0;
456960366cfSKarsten Keil if (finddsp->pcm_slot_tx >= 0 &&
457960366cfSKarsten Keil finddsp->pcm_slot_tx < sizeof(freeslots))
4589e9540b8SAdrian Bunk freeslots[finddsp->pcm_slot_tx] = 0;
459960366cfSKarsten Keil }
460960366cfSKarsten Keil }
461960366cfSKarsten Keil i = 0;
462960366cfSKarsten Keil ii = dsp->features.pcm_slots;
463960366cfSKarsten Keil while (i < ii) {
464960366cfSKarsten Keil if (freeslots[i])
465960366cfSKarsten Keil break;
466960366cfSKarsten Keil i++;
467960366cfSKarsten Keil }
468960366cfSKarsten Keil if (i == ii) {
469960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
470960366cfSKarsten Keil printk(KERN_DEBUG
471960366cfSKarsten Keil "%s no slot available for echo\n",
472960366cfSKarsten Keil __func__);
473960366cfSKarsten Keil /* no more slots available */
474bc138ec4SAndreas Eversberg dsp->echo.software = 1;
475960366cfSKarsten Keil return;
476960366cfSKarsten Keil }
477960366cfSKarsten Keil /* assign free slot */
478960366cfSKarsten Keil dsp->pcm_slot_tx = i;
479960366cfSKarsten Keil dsp->pcm_slot_rx = i;
480960366cfSKarsten Keil dsp->pcm_bank_tx = 2; /* loop */
481960366cfSKarsten Keil dsp->pcm_bank_rx = 2;
482960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
483960366cfSKarsten Keil printk(KERN_DEBUG
484960366cfSKarsten Keil "%s assign echo for %s using slot %d\n",
485960366cfSKarsten Keil __func__, dsp->name, dsp->pcm_slot_tx);
486960366cfSKarsten Keil dsp_cmx_hw_message(dsp, MISDN_CTRL_HFC_PCM_CONN,
487960366cfSKarsten Keil dsp->pcm_slot_tx, 2, dsp->pcm_slot_rx, 2);
488bc138ec4SAndreas Eversberg dsp->echo.hardware = 1;
489960366cfSKarsten Keil return;
490960366cfSKarsten Keil }
491960366cfSKarsten Keil
492960366cfSKarsten Keil /* conf gets updated (all members) */
493960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
494960366cfSKarsten Keil printk(KERN_DEBUG "%s checking conference %d\n",
495960366cfSKarsten Keil __func__, conf->id);
496960366cfSKarsten Keil
497960366cfSKarsten Keil if (list_empty(&conf->mlist)) {
498971bd8faSMasanari Iida printk(KERN_ERR "%s: conference without members\n",
499960366cfSKarsten Keil __func__);
500960366cfSKarsten Keil return;
501960366cfSKarsten Keil }
502960366cfSKarsten Keil member = list_entry(conf->mlist.next, struct dsp_conf_member, list);
503960366cfSKarsten Keil same_hfc = member->dsp->features.hfc_id;
504960366cfSKarsten Keil same_pcm = member->dsp->features.pcm_id;
505960366cfSKarsten Keil /* check all members in our conference */
506960366cfSKarsten Keil list_for_each_entry(member, &conf->mlist, list) {
507960366cfSKarsten Keil /* check if member uses mixing */
508960366cfSKarsten Keil if (member->dsp->tx_mix) {
509960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
510960366cfSKarsten Keil printk(KERN_DEBUG
511960366cfSKarsten Keil "%s dsp %s cannot form a conf, because "
512960366cfSKarsten Keil "tx_mix is turned on\n", __func__,
513960366cfSKarsten Keil member->dsp->name);
514960366cfSKarsten Keil conf_software:
515960366cfSKarsten Keil list_for_each_entry(member, &conf->mlist, list) {
516960366cfSKarsten Keil dsp = member->dsp;
517960366cfSKarsten Keil /* remove HFC conference if enabled */
518960366cfSKarsten Keil if (dsp->hfc_conf >= 0) {
519960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
520960366cfSKarsten Keil printk(KERN_DEBUG
521960366cfSKarsten Keil "%s removing %s from HFC "
522960366cfSKarsten Keil "conf %d because not "
523960366cfSKarsten Keil "possible with hardware\n",
524960366cfSKarsten Keil __func__,
525960366cfSKarsten Keil dsp->name,
526960366cfSKarsten Keil dsp->hfc_conf);
527960366cfSKarsten Keil dsp_cmx_hw_message(dsp,
528960366cfSKarsten Keil MISDN_CTRL_HFC_CONF_SPLIT,
529960366cfSKarsten Keil 0, 0, 0, 0);
530960366cfSKarsten Keil dsp->hfc_conf = -1;
531960366cfSKarsten Keil }
532960366cfSKarsten Keil /* remove PCM slot if assigned */
533960366cfSKarsten Keil if (dsp->pcm_slot_tx >= 0 ||
534960366cfSKarsten Keil dsp->pcm_slot_rx >= 0) {
535960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
536960366cfSKarsten Keil printk(KERN_DEBUG "%s removing "
537960366cfSKarsten Keil "%s from PCM slot %d (TX)"
538960366cfSKarsten Keil " slot %d (RX) because not"
539960366cfSKarsten Keil " possible with hardware\n",
540960366cfSKarsten Keil __func__,
541960366cfSKarsten Keil dsp->name,
542960366cfSKarsten Keil dsp->pcm_slot_tx,
543960366cfSKarsten Keil dsp->pcm_slot_rx);
544960366cfSKarsten Keil dsp_cmx_hw_message(dsp,
545960366cfSKarsten Keil MISDN_CTRL_HFC_PCM_DISC,
546960366cfSKarsten Keil 0, 0, 0, 0);
547960366cfSKarsten Keil dsp->pcm_slot_tx = -1;
548960366cfSKarsten Keil dsp->pcm_bank_tx = -1;
549960366cfSKarsten Keil dsp->pcm_slot_rx = -1;
550960366cfSKarsten Keil dsp->pcm_bank_rx = -1;
551960366cfSKarsten Keil }
552960366cfSKarsten Keil }
553960366cfSKarsten Keil conf->hardware = 0;
554960366cfSKarsten Keil conf->software = 1;
555960366cfSKarsten Keil return;
556960366cfSKarsten Keil }
557960366cfSKarsten Keil /* check if member has echo turned on */
558bc138ec4SAndreas Eversberg if (member->dsp->echo.hardware || member->dsp->echo.software) {
559960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
560960366cfSKarsten Keil printk(KERN_DEBUG
561960366cfSKarsten Keil "%s dsp %s cannot form a conf, because "
562960366cfSKarsten Keil "echo is turned on\n", __func__,
563960366cfSKarsten Keil member->dsp->name);
564960366cfSKarsten Keil goto conf_software;
565960366cfSKarsten Keil }
566960366cfSKarsten Keil /* check if member has tx_mix turned on */
567960366cfSKarsten Keil if (member->dsp->tx_mix) {
568960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
569960366cfSKarsten Keil printk(KERN_DEBUG
570960366cfSKarsten Keil "%s dsp %s cannot form a conf, because "
571960366cfSKarsten Keil "tx_mix is turned on\n",
572960366cfSKarsten Keil __func__, member->dsp->name);
573960366cfSKarsten Keil goto conf_software;
574960366cfSKarsten Keil }
575960366cfSKarsten Keil /* check if member changes volume at an not suppoted level */
576960366cfSKarsten Keil if (member->dsp->tx_volume) {
577960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
578960366cfSKarsten Keil printk(KERN_DEBUG
579960366cfSKarsten Keil "%s dsp %s cannot form a conf, because "
580960366cfSKarsten Keil "tx_volume is changed\n",
581960366cfSKarsten Keil __func__, member->dsp->name);
582960366cfSKarsten Keil goto conf_software;
583960366cfSKarsten Keil }
584960366cfSKarsten Keil if (member->dsp->rx_volume) {
585960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
586960366cfSKarsten Keil printk(KERN_DEBUG
587960366cfSKarsten Keil "%s dsp %s cannot form a conf, because "
588960366cfSKarsten Keil "rx_volume is changed\n",
589960366cfSKarsten Keil __func__, member->dsp->name);
590960366cfSKarsten Keil goto conf_software;
591960366cfSKarsten Keil }
592960366cfSKarsten Keil /* check if tx-data turned on */
593960366cfSKarsten Keil if (member->dsp->tx_data) {
594960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
595960366cfSKarsten Keil printk(KERN_DEBUG
596bc138ec4SAndreas Eversberg "%s dsp %s tx_data is turned on\n",
597960366cfSKarsten Keil __func__, member->dsp->name);
598bc138ec4SAndreas Eversberg tx_data = 1;
599960366cfSKarsten Keil }
600960366cfSKarsten Keil /* check if pipeline exists */
601960366cfSKarsten Keil if (member->dsp->pipeline.inuse) {
602960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
603960366cfSKarsten Keil printk(KERN_DEBUG
604960366cfSKarsten Keil "%s dsp %s cannot form a conf, because "
605960366cfSKarsten Keil "pipeline exists\n", __func__,
606960366cfSKarsten Keil member->dsp->name);
607960366cfSKarsten Keil goto conf_software;
608960366cfSKarsten Keil }
609960366cfSKarsten Keil /* check if encryption is enabled */
610960366cfSKarsten Keil if (member->dsp->bf_enable) {
611960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
612960366cfSKarsten Keil printk(KERN_DEBUG "%s dsp %s cannot form a "
613960366cfSKarsten Keil "conf, because encryption is enabled\n",
614960366cfSKarsten Keil __func__, member->dsp->name);
615960366cfSKarsten Keil goto conf_software;
616960366cfSKarsten Keil }
617960366cfSKarsten Keil /* check if member is on a card with PCM support */
618960366cfSKarsten Keil if (member->dsp->features.pcm_id < 0) {
619960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
620960366cfSKarsten Keil printk(KERN_DEBUG
621960366cfSKarsten Keil "%s dsp %s cannot form a conf, because "
622960366cfSKarsten Keil "dsp has no PCM bus\n",
623960366cfSKarsten Keil __func__, member->dsp->name);
624960366cfSKarsten Keil goto conf_software;
625960366cfSKarsten Keil }
626960366cfSKarsten Keil /* check if relations are on the same PCM bus */
627960366cfSKarsten Keil if (member->dsp->features.pcm_id != same_pcm) {
628960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
629960366cfSKarsten Keil printk(KERN_DEBUG
630960366cfSKarsten Keil "%s dsp %s cannot form a conf, because "
631960366cfSKarsten Keil "dsp is on a different PCM bus than the "
632960366cfSKarsten Keil "first dsp\n",
633960366cfSKarsten Keil __func__, member->dsp->name);
634960366cfSKarsten Keil goto conf_software;
635960366cfSKarsten Keil }
636960366cfSKarsten Keil /* determine if members are on the same hfc chip */
637960366cfSKarsten Keil if (same_hfc != member->dsp->features.hfc_id)
638960366cfSKarsten Keil same_hfc = -1;
639960366cfSKarsten Keil /* if there are members already in a conference */
640960366cfSKarsten Keil if (current_conf < 0 && member->dsp->hfc_conf >= 0)
641960366cfSKarsten Keil current_conf = member->dsp->hfc_conf;
642960366cfSKarsten Keil /* if any member is not in a conference */
643960366cfSKarsten Keil if (member->dsp->hfc_conf < 0)
644960366cfSKarsten Keil all_conf = 0;
645960366cfSKarsten Keil
646960366cfSKarsten Keil memb++;
647960366cfSKarsten Keil }
648960366cfSKarsten Keil
649960366cfSKarsten Keil /* if no member, this is an error */
650960366cfSKarsten Keil if (memb < 1)
651960366cfSKarsten Keil return;
652960366cfSKarsten Keil
653960366cfSKarsten Keil /* one member */
654960366cfSKarsten Keil if (memb == 1) {
655960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
656960366cfSKarsten Keil printk(KERN_DEBUG
657960366cfSKarsten Keil "%s conf %d cannot form a HW conference, "
658960366cfSKarsten Keil "because dsp is alone\n", __func__, conf->id);
659960366cfSKarsten Keil conf->hardware = 0;
660960366cfSKarsten Keil conf->software = 0;
661960366cfSKarsten Keil member = list_entry(conf->mlist.next, struct dsp_conf_member,
662960366cfSKarsten Keil list);
663960366cfSKarsten Keil dsp = member->dsp;
664960366cfSKarsten Keil goto one_member;
665960366cfSKarsten Keil }
666960366cfSKarsten Keil
667960366cfSKarsten Keil /*
668960366cfSKarsten Keil * ok, now we are sure that all members are on the same pcm.
669960366cfSKarsten Keil * now we will see if we have only two members, so we can do
670960366cfSKarsten Keil * crossconnections, which don't have any limitations.
671960366cfSKarsten Keil */
672960366cfSKarsten Keil
673960366cfSKarsten Keil /* if we have only two members */
674960366cfSKarsten Keil if (memb == 2) {
675960366cfSKarsten Keil member = list_entry(conf->mlist.next, struct dsp_conf_member,
676960366cfSKarsten Keil list);
677960366cfSKarsten Keil nextm = list_entry(member->list.next, struct dsp_conf_member,
678960366cfSKarsten Keil list);
679960366cfSKarsten Keil /* remove HFC conference if enabled */
680960366cfSKarsten Keil if (member->dsp->hfc_conf >= 0) {
681960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
682960366cfSKarsten Keil printk(KERN_DEBUG
683960366cfSKarsten Keil "%s removing %s from HFC conf %d because "
684960366cfSKarsten Keil "two parties require only a PCM slot\n",
685960366cfSKarsten Keil __func__, member->dsp->name,
686960366cfSKarsten Keil member->dsp->hfc_conf);
687960366cfSKarsten Keil dsp_cmx_hw_message(member->dsp,
688960366cfSKarsten Keil MISDN_CTRL_HFC_CONF_SPLIT, 0, 0, 0, 0);
689960366cfSKarsten Keil member->dsp->hfc_conf = -1;
690960366cfSKarsten Keil }
691960366cfSKarsten Keil if (nextm->dsp->hfc_conf >= 0) {
692960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
693960366cfSKarsten Keil printk(KERN_DEBUG
694960366cfSKarsten Keil "%s removing %s from HFC conf %d because "
695960366cfSKarsten Keil "two parties require only a PCM slot\n",
696960366cfSKarsten Keil __func__, nextm->dsp->name,
697960366cfSKarsten Keil nextm->dsp->hfc_conf);
698960366cfSKarsten Keil dsp_cmx_hw_message(nextm->dsp,
699960366cfSKarsten Keil MISDN_CTRL_HFC_CONF_SPLIT, 0, 0, 0, 0);
700960366cfSKarsten Keil nextm->dsp->hfc_conf = -1;
701960366cfSKarsten Keil }
702960366cfSKarsten Keil /* if members have two banks (and not on the same chip) */
703960366cfSKarsten Keil if (member->dsp->features.pcm_banks > 1 &&
704960366cfSKarsten Keil nextm->dsp->features.pcm_banks > 1 &&
705960366cfSKarsten Keil member->dsp->features.hfc_id !=
706960366cfSKarsten Keil nextm->dsp->features.hfc_id) {
707960366cfSKarsten Keil /* if both members have same slots with crossed banks */
708960366cfSKarsten Keil if (member->dsp->pcm_slot_tx >= 0 &&
709960366cfSKarsten Keil member->dsp->pcm_slot_rx >= 0 &&
710960366cfSKarsten Keil nextm->dsp->pcm_slot_tx >= 0 &&
711960366cfSKarsten Keil nextm->dsp->pcm_slot_rx >= 0 &&
712960366cfSKarsten Keil nextm->dsp->pcm_slot_tx ==
713960366cfSKarsten Keil member->dsp->pcm_slot_rx &&
714960366cfSKarsten Keil nextm->dsp->pcm_slot_rx ==
715960366cfSKarsten Keil member->dsp->pcm_slot_tx &&
716960366cfSKarsten Keil nextm->dsp->pcm_slot_tx ==
717960366cfSKarsten Keil member->dsp->pcm_slot_tx &&
718960366cfSKarsten Keil member->dsp->pcm_bank_tx !=
719960366cfSKarsten Keil member->dsp->pcm_bank_rx &&
720960366cfSKarsten Keil nextm->dsp->pcm_bank_tx !=
721960366cfSKarsten Keil nextm->dsp->pcm_bank_rx) {
722960366cfSKarsten Keil /* all members have same slot */
723960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
724960366cfSKarsten Keil printk(KERN_DEBUG
725960366cfSKarsten Keil "%s dsp %s & %s stay joined on "
726960366cfSKarsten Keil "PCM slot %d bank %d (TX) bank %d "
727960366cfSKarsten Keil "(RX) (on different chips)\n",
728960366cfSKarsten Keil __func__,
729960366cfSKarsten Keil member->dsp->name,
730960366cfSKarsten Keil nextm->dsp->name,
731960366cfSKarsten Keil member->dsp->pcm_slot_tx,
732960366cfSKarsten Keil member->dsp->pcm_bank_tx,
733960366cfSKarsten Keil member->dsp->pcm_bank_rx);
73452a637c2SAndreas Eversberg conf->hardware = 1;
73552a637c2SAndreas Eversberg conf->software = tx_data;
736960366cfSKarsten Keil return;
737960366cfSKarsten Keil }
738960366cfSKarsten Keil /* find a new slot */
739960366cfSKarsten Keil memset(freeslots, 1, sizeof(freeslots));
740960366cfSKarsten Keil list_for_each_entry(dsp, &dsp_ilist, list) {
741960366cfSKarsten Keil if (dsp != member->dsp &&
742960366cfSKarsten Keil dsp != nextm->dsp &&
743960366cfSKarsten Keil member->dsp->features.pcm_id ==
744960366cfSKarsten Keil dsp->features.pcm_id) {
745960366cfSKarsten Keil if (dsp->pcm_slot_rx >= 0 &&
746960366cfSKarsten Keil dsp->pcm_slot_rx <
747960366cfSKarsten Keil sizeof(freeslots))
74883a8a55bSAndreas Eversberg freeslots[dsp->pcm_slot_rx] = 0;
749960366cfSKarsten Keil if (dsp->pcm_slot_tx >= 0 &&
750960366cfSKarsten Keil dsp->pcm_slot_tx <
751960366cfSKarsten Keil sizeof(freeslots))
75283a8a55bSAndreas Eversberg freeslots[dsp->pcm_slot_tx] = 0;
753960366cfSKarsten Keil }
754960366cfSKarsten Keil }
755960366cfSKarsten Keil i = 0;
756960366cfSKarsten Keil ii = member->dsp->features.pcm_slots;
757960366cfSKarsten Keil while (i < ii) {
758960366cfSKarsten Keil if (freeslots[i])
759960366cfSKarsten Keil break;
760960366cfSKarsten Keil i++;
761960366cfSKarsten Keil }
762960366cfSKarsten Keil if (i == ii) {
763960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
764960366cfSKarsten Keil printk(KERN_DEBUG
765960366cfSKarsten Keil "%s no slot available for "
766960366cfSKarsten Keil "%s & %s\n", __func__,
767960366cfSKarsten Keil member->dsp->name,
768960366cfSKarsten Keil nextm->dsp->name);
769960366cfSKarsten Keil /* no more slots available */
770960366cfSKarsten Keil goto conf_software;
771960366cfSKarsten Keil }
772960366cfSKarsten Keil /* assign free slot */
773960366cfSKarsten Keil member->dsp->pcm_slot_tx = i;
774960366cfSKarsten Keil member->dsp->pcm_slot_rx = i;
775960366cfSKarsten Keil nextm->dsp->pcm_slot_tx = i;
776960366cfSKarsten Keil nextm->dsp->pcm_slot_rx = i;
777960366cfSKarsten Keil member->dsp->pcm_bank_rx = 0;
778960366cfSKarsten Keil member->dsp->pcm_bank_tx = 1;
779960366cfSKarsten Keil nextm->dsp->pcm_bank_rx = 1;
780960366cfSKarsten Keil nextm->dsp->pcm_bank_tx = 0;
781960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
782960366cfSKarsten Keil printk(KERN_DEBUG
783960366cfSKarsten Keil "%s adding %s & %s to new PCM slot %d "
784960366cfSKarsten Keil "(TX and RX on different chips) because "
785960366cfSKarsten Keil "both members have not same slots\n",
786960366cfSKarsten Keil __func__,
787960366cfSKarsten Keil member->dsp->name,
788960366cfSKarsten Keil nextm->dsp->name,
789960366cfSKarsten Keil member->dsp->pcm_slot_tx);
790960366cfSKarsten Keil dsp_cmx_hw_message(member->dsp, MISDN_CTRL_HFC_PCM_CONN,
791960366cfSKarsten Keil member->dsp->pcm_slot_tx, member->dsp->pcm_bank_tx,
792960366cfSKarsten Keil member->dsp->pcm_slot_rx, member->dsp->pcm_bank_rx);
793960366cfSKarsten Keil dsp_cmx_hw_message(nextm->dsp, MISDN_CTRL_HFC_PCM_CONN,
794960366cfSKarsten Keil nextm->dsp->pcm_slot_tx, nextm->dsp->pcm_bank_tx,
795960366cfSKarsten Keil nextm->dsp->pcm_slot_rx, nextm->dsp->pcm_bank_rx);
796960366cfSKarsten Keil conf->hardware = 1;
797bc138ec4SAndreas Eversberg conf->software = tx_data;
798960366cfSKarsten Keil return;
799960366cfSKarsten Keil /* if members have one bank (or on the same chip) */
800960366cfSKarsten Keil } else {
801960366cfSKarsten Keil /* if both members have different crossed slots */
802960366cfSKarsten Keil if (member->dsp->pcm_slot_tx >= 0 &&
803960366cfSKarsten Keil member->dsp->pcm_slot_rx >= 0 &&
804960366cfSKarsten Keil nextm->dsp->pcm_slot_tx >= 0 &&
805960366cfSKarsten Keil nextm->dsp->pcm_slot_rx >= 0 &&
806960366cfSKarsten Keil nextm->dsp->pcm_slot_tx ==
807960366cfSKarsten Keil member->dsp->pcm_slot_rx &&
808960366cfSKarsten Keil nextm->dsp->pcm_slot_rx ==
809960366cfSKarsten Keil member->dsp->pcm_slot_tx &&
810960366cfSKarsten Keil member->dsp->pcm_slot_tx !=
811960366cfSKarsten Keil member->dsp->pcm_slot_rx &&
812960366cfSKarsten Keil member->dsp->pcm_bank_tx == 0 &&
813960366cfSKarsten Keil member->dsp->pcm_bank_rx == 0 &&
814960366cfSKarsten Keil nextm->dsp->pcm_bank_tx == 0 &&
815960366cfSKarsten Keil nextm->dsp->pcm_bank_rx == 0) {
816960366cfSKarsten Keil /* all members have same slot */
817960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
818960366cfSKarsten Keil printk(KERN_DEBUG
819960366cfSKarsten Keil "%s dsp %s & %s stay joined on PCM "
820960366cfSKarsten Keil "slot %d (TX) %d (RX) on same chip "
821960366cfSKarsten Keil "or one bank PCM)\n", __func__,
822960366cfSKarsten Keil member->dsp->name,
823960366cfSKarsten Keil nextm->dsp->name,
824960366cfSKarsten Keil member->dsp->pcm_slot_tx,
825960366cfSKarsten Keil member->dsp->pcm_slot_rx);
82652a637c2SAndreas Eversberg conf->hardware = 1;
82752a637c2SAndreas Eversberg conf->software = tx_data;
828960366cfSKarsten Keil return;
829960366cfSKarsten Keil }
830960366cfSKarsten Keil /* find two new slot */
831960366cfSKarsten Keil memset(freeslots, 1, sizeof(freeslots));
832960366cfSKarsten Keil list_for_each_entry(dsp, &dsp_ilist, list) {
833960366cfSKarsten Keil if (dsp != member->dsp &&
834960366cfSKarsten Keil dsp != nextm->dsp &&
835960366cfSKarsten Keil member->dsp->features.pcm_id ==
836960366cfSKarsten Keil dsp->features.pcm_id) {
837960366cfSKarsten Keil if (dsp->pcm_slot_rx >= 0 &&
838960366cfSKarsten Keil dsp->pcm_slot_rx <
839960366cfSKarsten Keil sizeof(freeslots))
84083a8a55bSAndreas Eversberg freeslots[dsp->pcm_slot_rx] = 0;
841960366cfSKarsten Keil if (dsp->pcm_slot_tx >= 0 &&
842960366cfSKarsten Keil dsp->pcm_slot_tx <
843960366cfSKarsten Keil sizeof(freeslots))
84483a8a55bSAndreas Eversberg freeslots[dsp->pcm_slot_tx] = 0;
845960366cfSKarsten Keil }
846960366cfSKarsten Keil }
847960366cfSKarsten Keil i1 = 0;
848960366cfSKarsten Keil ii = member->dsp->features.pcm_slots;
849960366cfSKarsten Keil while (i1 < ii) {
850960366cfSKarsten Keil if (freeslots[i1])
851960366cfSKarsten Keil break;
852960366cfSKarsten Keil i1++;
853960366cfSKarsten Keil }
854960366cfSKarsten Keil if (i1 == ii) {
855960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
856960366cfSKarsten Keil printk(KERN_DEBUG
857960366cfSKarsten Keil "%s no slot available "
858960366cfSKarsten Keil "for %s & %s\n", __func__,
859960366cfSKarsten Keil member->dsp->name,
860960366cfSKarsten Keil nextm->dsp->name);
861960366cfSKarsten Keil /* no more slots available */
862960366cfSKarsten Keil goto conf_software;
863960366cfSKarsten Keil }
864960366cfSKarsten Keil i2 = i1 + 1;
865960366cfSKarsten Keil while (i2 < ii) {
866960366cfSKarsten Keil if (freeslots[i2])
867960366cfSKarsten Keil break;
868960366cfSKarsten Keil i2++;
869960366cfSKarsten Keil }
870960366cfSKarsten Keil if (i2 == ii) {
871960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
872960366cfSKarsten Keil printk(KERN_DEBUG
873960366cfSKarsten Keil "%s no slot available "
874960366cfSKarsten Keil "for %s & %s\n",
875960366cfSKarsten Keil __func__,
876960366cfSKarsten Keil member->dsp->name,
877960366cfSKarsten Keil nextm->dsp->name);
878960366cfSKarsten Keil /* no more slots available */
879960366cfSKarsten Keil goto conf_software;
880960366cfSKarsten Keil }
881960366cfSKarsten Keil /* assign free slots */
882960366cfSKarsten Keil member->dsp->pcm_slot_tx = i1;
883960366cfSKarsten Keil member->dsp->pcm_slot_rx = i2;
884960366cfSKarsten Keil nextm->dsp->pcm_slot_tx = i2;
885960366cfSKarsten Keil nextm->dsp->pcm_slot_rx = i1;
886960366cfSKarsten Keil member->dsp->pcm_bank_rx = 0;
887960366cfSKarsten Keil member->dsp->pcm_bank_tx = 0;
888960366cfSKarsten Keil nextm->dsp->pcm_bank_rx = 0;
889960366cfSKarsten Keil nextm->dsp->pcm_bank_tx = 0;
890960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
891960366cfSKarsten Keil printk(KERN_DEBUG
892960366cfSKarsten Keil "%s adding %s & %s to new PCM slot %d "
893960366cfSKarsten Keil "(TX) %d (RX) on same chip or one bank "
894960366cfSKarsten Keil "PCM, because both members have not "
895960366cfSKarsten Keil "crossed slots\n", __func__,
896960366cfSKarsten Keil member->dsp->name,
897960366cfSKarsten Keil nextm->dsp->name,
898960366cfSKarsten Keil member->dsp->pcm_slot_tx,
899960366cfSKarsten Keil member->dsp->pcm_slot_rx);
900960366cfSKarsten Keil dsp_cmx_hw_message(member->dsp, MISDN_CTRL_HFC_PCM_CONN,
901960366cfSKarsten Keil member->dsp->pcm_slot_tx, member->dsp->pcm_bank_tx,
902960366cfSKarsten Keil member->dsp->pcm_slot_rx, member->dsp->pcm_bank_rx);
903960366cfSKarsten Keil dsp_cmx_hw_message(nextm->dsp, MISDN_CTRL_HFC_PCM_CONN,
904960366cfSKarsten Keil nextm->dsp->pcm_slot_tx, nextm->dsp->pcm_bank_tx,
905960366cfSKarsten Keil nextm->dsp->pcm_slot_rx, nextm->dsp->pcm_bank_rx);
906960366cfSKarsten Keil conf->hardware = 1;
907bc138ec4SAndreas Eversberg conf->software = tx_data;
908960366cfSKarsten Keil return;
909960366cfSKarsten Keil }
910960366cfSKarsten Keil }
911960366cfSKarsten Keil
912960366cfSKarsten Keil /*
913960366cfSKarsten Keil * if we have more than two, we may check if we have a conference
914960366cfSKarsten Keil * unit available on the chip. also all members must be on the same
915960366cfSKarsten Keil */
916960366cfSKarsten Keil
917960366cfSKarsten Keil /* if not the same HFC chip */
918960366cfSKarsten Keil if (same_hfc < 0) {
919960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
920960366cfSKarsten Keil printk(KERN_DEBUG
921960366cfSKarsten Keil "%s conference %d cannot be formed, because "
922960366cfSKarsten Keil "members are on different chips or not "
923960366cfSKarsten Keil "on HFC chip\n",
924960366cfSKarsten Keil __func__, conf->id);
925960366cfSKarsten Keil goto conf_software;
926960366cfSKarsten Keil }
927960366cfSKarsten Keil
928960366cfSKarsten Keil /* for more than two members.. */
929960366cfSKarsten Keil
930960366cfSKarsten Keil /* if all members already have the same conference */
93152a637c2SAndreas Eversberg if (all_conf) {
93252a637c2SAndreas Eversberg conf->hardware = 1;
93352a637c2SAndreas Eversberg conf->software = tx_data;
934960366cfSKarsten Keil return;
93552a637c2SAndreas Eversberg }
936960366cfSKarsten Keil
937960366cfSKarsten Keil /*
938960366cfSKarsten Keil * if there is an existing conference, but not all members have joined
939960366cfSKarsten Keil */
940960366cfSKarsten Keil if (current_conf >= 0) {
941960366cfSKarsten Keil join_members:
942960366cfSKarsten Keil list_for_each_entry(member, &conf->mlist, list) {
943db9bb63aSKarsten Keil /* if no conference engine on our chip, change to
944db9bb63aSKarsten Keil * software */
945db9bb63aSKarsten Keil if (!member->dsp->features.hfc_conf)
946db9bb63aSKarsten Keil goto conf_software;
947c6a2e587SAndreas Eversberg /* in case of hdlc, change to software */
948c6a2e587SAndreas Eversberg if (member->dsp->hdlc)
949c6a2e587SAndreas Eversberg goto conf_software;
950960366cfSKarsten Keil /* join to current conference */
951960366cfSKarsten Keil if (member->dsp->hfc_conf == current_conf)
952960366cfSKarsten Keil continue;
953960366cfSKarsten Keil /* get a free timeslot first */
954960366cfSKarsten Keil memset(freeslots, 1, sizeof(freeslots));
955960366cfSKarsten Keil list_for_each_entry(dsp, &dsp_ilist, list) {
956960366cfSKarsten Keil /*
957960366cfSKarsten Keil * not checking current member, because
958960366cfSKarsten Keil * slot will be overwritten.
959960366cfSKarsten Keil */
960960366cfSKarsten Keil if (
961960366cfSKarsten Keil dsp != member->dsp &&
962960366cfSKarsten Keil /* dsp must be on the same PCM */
963960366cfSKarsten Keil member->dsp->features.pcm_id ==
964960366cfSKarsten Keil dsp->features.pcm_id) {
965960366cfSKarsten Keil /* dsp must be on a slot */
966960366cfSKarsten Keil if (dsp->pcm_slot_tx >= 0 &&
967960366cfSKarsten Keil dsp->pcm_slot_tx <
968960366cfSKarsten Keil sizeof(freeslots))
969960366cfSKarsten Keil freeslots[dsp->pcm_slot_tx] = 0;
970960366cfSKarsten Keil if (dsp->pcm_slot_rx >= 0 &&
971960366cfSKarsten Keil dsp->pcm_slot_rx <
972960366cfSKarsten Keil sizeof(freeslots))
973960366cfSKarsten Keil freeslots[dsp->pcm_slot_rx] = 0;
974960366cfSKarsten Keil }
975960366cfSKarsten Keil }
976960366cfSKarsten Keil i = 0;
977960366cfSKarsten Keil ii = member->dsp->features.pcm_slots;
978960366cfSKarsten Keil while (i < ii) {
979960366cfSKarsten Keil if (freeslots[i])
980960366cfSKarsten Keil break;
981960366cfSKarsten Keil i++;
982960366cfSKarsten Keil }
983960366cfSKarsten Keil if (i == ii) {
984960366cfSKarsten Keil /* no more slots available */
985960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
986960366cfSKarsten Keil printk(KERN_DEBUG
987960366cfSKarsten Keil "%s conference %d cannot be formed,"
988960366cfSKarsten Keil " because no slot free\n",
989960366cfSKarsten Keil __func__, conf->id);
990960366cfSKarsten Keil goto conf_software;
991960366cfSKarsten Keil }
992960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
993960366cfSKarsten Keil printk(KERN_DEBUG
994960366cfSKarsten Keil "%s changing dsp %s to HW conference "
995960366cfSKarsten Keil "%d slot %d\n", __func__,
996960366cfSKarsten Keil member->dsp->name, current_conf, i);
997960366cfSKarsten Keil /* assign free slot & set PCM & join conf */
998960366cfSKarsten Keil member->dsp->pcm_slot_tx = i;
999960366cfSKarsten Keil member->dsp->pcm_slot_rx = i;
1000960366cfSKarsten Keil member->dsp->pcm_bank_tx = 2; /* loop */
1001960366cfSKarsten Keil member->dsp->pcm_bank_rx = 2;
1002960366cfSKarsten Keil member->dsp->hfc_conf = current_conf;
1003960366cfSKarsten Keil dsp_cmx_hw_message(member->dsp, MISDN_CTRL_HFC_PCM_CONN,
1004960366cfSKarsten Keil i, 2, i, 2);
1005960366cfSKarsten Keil dsp_cmx_hw_message(member->dsp,
1006960366cfSKarsten Keil MISDN_CTRL_HFC_CONF_JOIN, current_conf, 0, 0, 0);
1007960366cfSKarsten Keil }
100852a637c2SAndreas Eversberg conf->hardware = 1;
100952a637c2SAndreas Eversberg conf->software = tx_data;
1010960366cfSKarsten Keil return;
1011960366cfSKarsten Keil }
1012960366cfSKarsten Keil
1013960366cfSKarsten Keil /*
1014960366cfSKarsten Keil * no member is in a conference yet, so we find a free one
1015960366cfSKarsten Keil */
1016960366cfSKarsten Keil memset(freeunits, 1, sizeof(freeunits));
1017960366cfSKarsten Keil list_for_each_entry(dsp, &dsp_ilist, list) {
1018960366cfSKarsten Keil /* dsp must be on the same chip */
1019960366cfSKarsten Keil if (dsp->features.hfc_id == same_hfc &&
1020960366cfSKarsten Keil /* dsp must have joined a HW conference */
1021960366cfSKarsten Keil dsp->hfc_conf >= 0 &&
1022960366cfSKarsten Keil /* slot must be within range */
1023960366cfSKarsten Keil dsp->hfc_conf < 8)
1024960366cfSKarsten Keil freeunits[dsp->hfc_conf] = 0;
1025960366cfSKarsten Keil }
1026960366cfSKarsten Keil i = 0;
1027960366cfSKarsten Keil ii = 8;
1028960366cfSKarsten Keil while (i < ii) {
1029960366cfSKarsten Keil if (freeunits[i])
1030960366cfSKarsten Keil break;
1031960366cfSKarsten Keil i++;
1032960366cfSKarsten Keil }
1033960366cfSKarsten Keil if (i == ii) {
1034960366cfSKarsten Keil /* no more conferences available */
1035960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
1036960366cfSKarsten Keil printk(KERN_DEBUG
1037960366cfSKarsten Keil "%s conference %d cannot be formed, because "
1038960366cfSKarsten Keil "no conference number free\n",
1039960366cfSKarsten Keil __func__, conf->id);
1040960366cfSKarsten Keil goto conf_software;
1041960366cfSKarsten Keil }
1042960366cfSKarsten Keil /* join all members */
1043960366cfSKarsten Keil current_conf = i;
1044960366cfSKarsten Keil goto join_members;
1045960366cfSKarsten Keil }
1046960366cfSKarsten Keil
1047960366cfSKarsten Keil
1048960366cfSKarsten Keil /*
1049960366cfSKarsten Keil * conf_id != 0: join or change conference
1050960366cfSKarsten Keil * conf_id == 0: split from conference if not already
1051960366cfSKarsten Keil */
1052960366cfSKarsten Keil int
dsp_cmx_conf(struct dsp * dsp,u32 conf_id)1053960366cfSKarsten Keil dsp_cmx_conf(struct dsp *dsp, u32 conf_id)
1054960366cfSKarsten Keil {
1055960366cfSKarsten Keil int err;
1056960366cfSKarsten Keil struct dsp_conf *conf;
1057960366cfSKarsten Keil struct dsp_conf_member *member;
1058960366cfSKarsten Keil
1059960366cfSKarsten Keil /* if conference doesn't change */
1060960366cfSKarsten Keil if (dsp->conf_id == conf_id)
1061960366cfSKarsten Keil return 0;
1062960366cfSKarsten Keil
1063960366cfSKarsten Keil /* first remove us from current conf */
1064960366cfSKarsten Keil if (dsp->conf_id) {
1065960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
1066960366cfSKarsten Keil printk(KERN_DEBUG "removing us from conference %d\n",
1067960366cfSKarsten Keil dsp->conf->id);
1068960366cfSKarsten Keil /* remove us from conf */
1069960366cfSKarsten Keil conf = dsp->conf;
1070960366cfSKarsten Keil err = dsp_cmx_del_conf_member(dsp);
1071960366cfSKarsten Keil if (err)
1072960366cfSKarsten Keil return err;
1073960366cfSKarsten Keil dsp->conf_id = 0;
1074960366cfSKarsten Keil
1075960366cfSKarsten Keil /* update hardware */
1076960366cfSKarsten Keil dsp_cmx_hardware(NULL, dsp);
1077960366cfSKarsten Keil
1078960366cfSKarsten Keil /* conf now empty? */
1079960366cfSKarsten Keil if (list_empty(&conf->mlist)) {
1080960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
1081960366cfSKarsten Keil printk(KERN_DEBUG
1082960366cfSKarsten Keil "conference is empty, so we remove it.\n");
1083960366cfSKarsten Keil err = dsp_cmx_del_conf(conf);
1084960366cfSKarsten Keil if (err)
1085960366cfSKarsten Keil return err;
1086960366cfSKarsten Keil } else {
1087960366cfSKarsten Keil /* update members left on conf */
1088960366cfSKarsten Keil dsp_cmx_hardware(conf, NULL);
1089960366cfSKarsten Keil }
1090960366cfSKarsten Keil }
1091960366cfSKarsten Keil
1092960366cfSKarsten Keil /* if split */
1093960366cfSKarsten Keil if (!conf_id)
1094960366cfSKarsten Keil return 0;
1095960366cfSKarsten Keil
1096960366cfSKarsten Keil /* now add us to conf */
1097960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
1098960366cfSKarsten Keil printk(KERN_DEBUG "searching conference %d\n",
1099960366cfSKarsten Keil conf_id);
1100960366cfSKarsten Keil conf = dsp_cmx_search_conf(conf_id);
1101960366cfSKarsten Keil if (!conf) {
1102960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
1103960366cfSKarsten Keil printk(KERN_DEBUG
1104960366cfSKarsten Keil "conference doesn't exist yet, creating.\n");
1105960366cfSKarsten Keil /* the conference doesn't exist, so we create */
1106960366cfSKarsten Keil conf = dsp_cmx_new_conf(conf_id);
1107960366cfSKarsten Keil if (!conf)
1108960366cfSKarsten Keil return -EINVAL;
1109960366cfSKarsten Keil } else if (!list_empty(&conf->mlist)) {
1110960366cfSKarsten Keil member = list_entry(conf->mlist.next, struct dsp_conf_member,
1111960366cfSKarsten Keil list);
1112960366cfSKarsten Keil if (dsp->hdlc && !member->dsp->hdlc) {
1113960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
1114960366cfSKarsten Keil printk(KERN_DEBUG
1115960366cfSKarsten Keil "cannot join transparent conference.\n");
1116960366cfSKarsten Keil return -EINVAL;
1117960366cfSKarsten Keil }
1118960366cfSKarsten Keil if (!dsp->hdlc && member->dsp->hdlc) {
1119960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
1120960366cfSKarsten Keil printk(KERN_DEBUG
1121960366cfSKarsten Keil "cannot join hdlc conference.\n");
1122960366cfSKarsten Keil return -EINVAL;
1123960366cfSKarsten Keil }
1124960366cfSKarsten Keil }
1125960366cfSKarsten Keil /* add conference member */
1126960366cfSKarsten Keil err = dsp_cmx_add_conf_member(dsp, conf);
1127960366cfSKarsten Keil if (err)
1128960366cfSKarsten Keil return err;
1129960366cfSKarsten Keil dsp->conf_id = conf_id;
1130960366cfSKarsten Keil
1131960366cfSKarsten Keil /* if we are alone, we do nothing! */
1132960366cfSKarsten Keil if (list_empty(&conf->mlist)) {
1133960366cfSKarsten Keil if (dsp_debug & DEBUG_DSP_CMX)
1134960366cfSKarsten Keil printk(KERN_DEBUG
1135960366cfSKarsten Keil "we are alone in this conference, so exit.\n");
1136960366cfSKarsten Keil /* update hardware */
1137960366cfSKarsten Keil dsp_cmx_hardware(NULL, dsp);
1138960366cfSKarsten Keil return 0;
1139960366cfSKarsten Keil }
1140960366cfSKarsten Keil
1141960366cfSKarsten Keil /* update members on conf */
1142960366cfSKarsten Keil dsp_cmx_hardware(conf, NULL);
1143960366cfSKarsten Keil
1144960366cfSKarsten Keil return 0;
1145960366cfSKarsten Keil }
1146960366cfSKarsten Keil
114787c5fa1bSAndreas Eversberg #ifdef CMX_DELAY_DEBUG
114887c5fa1bSAndreas Eversberg int delaycount;
114987c5fa1bSAndreas Eversberg static void
showdelay(struct dsp * dsp,int samples,int delay)115087c5fa1bSAndreas Eversberg showdelay(struct dsp *dsp, int samples, int delay)
115187c5fa1bSAndreas Eversberg {
115287c5fa1bSAndreas Eversberg char bar[] = "--------------------------------------------------|";
115387c5fa1bSAndreas Eversberg int sdelay;
115487c5fa1bSAndreas Eversberg
115587c5fa1bSAndreas Eversberg delaycount += samples;
115687c5fa1bSAndreas Eversberg if (delaycount < 8000)
115787c5fa1bSAndreas Eversberg return;
115887c5fa1bSAndreas Eversberg delaycount = 0;
115987c5fa1bSAndreas Eversberg
116087c5fa1bSAndreas Eversberg sdelay = delay * 50 / (dsp_poll << 2);
116187c5fa1bSAndreas Eversberg
116287c5fa1bSAndreas Eversberg printk(KERN_DEBUG "DELAY (%s) %3d >%s\n", dsp->name, delay,
116387c5fa1bSAndreas Eversberg sdelay > 50 ? "..." : bar + 50 - sdelay);
116487c5fa1bSAndreas Eversberg }
116587c5fa1bSAndreas Eversberg #endif
1166960366cfSKarsten Keil
1167960366cfSKarsten Keil /*
1168960366cfSKarsten Keil * audio data is received from card
1169960366cfSKarsten Keil */
1170960366cfSKarsten Keil void
dsp_cmx_receive(struct dsp * dsp,struct sk_buff * skb)1171960366cfSKarsten Keil dsp_cmx_receive(struct dsp *dsp, struct sk_buff *skb)
1172960366cfSKarsten Keil {
1173960366cfSKarsten Keil u8 *d, *p;
1174960366cfSKarsten Keil int len = skb->len;
1175960366cfSKarsten Keil struct mISDNhead *hh = mISDN_HEAD_P(skb);
1176960366cfSKarsten Keil int w, i, ii;
1177960366cfSKarsten Keil
1178960366cfSKarsten Keil /* check if we have sompen */
1179960366cfSKarsten Keil if (len < 1)
1180960366cfSKarsten Keil return;
1181960366cfSKarsten Keil
1182960366cfSKarsten Keil /* half of the buffer should be larger than maximum packet size */
1183960366cfSKarsten Keil if (len >= CMX_BUFF_HALF) {
1184960366cfSKarsten Keil printk(KERN_ERR
1185960366cfSKarsten Keil "%s line %d: packet from card is too large (%d bytes). "
1186960366cfSKarsten Keil "please make card send smaller packets OR increase "
1187960366cfSKarsten Keil "CMX_BUFF_SIZE\n", __FILE__, __LINE__, len);
1188960366cfSKarsten Keil return;
1189960366cfSKarsten Keil }
1190960366cfSKarsten Keil
1191960366cfSKarsten Keil /*
1192960366cfSKarsten Keil * initialize pointers if not already -
1193960366cfSKarsten Keil * also add delay if requested by PH_SIGNAL
1194960366cfSKarsten Keil */
1195960366cfSKarsten Keil if (dsp->rx_init) {
1196960366cfSKarsten Keil dsp->rx_init = 0;
1197960366cfSKarsten Keil if (dsp->features.unordered) {
1198960366cfSKarsten Keil dsp->rx_R = (hh->id & CMX_BUFF_MASK);
11998dd2f36fSAndreas Eversberg if (dsp->cmx_delay)
1200960366cfSKarsten Keil dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
1201960366cfSKarsten Keil & CMX_BUFF_MASK;
12028dd2f36fSAndreas Eversberg else
12038dd2f36fSAndreas Eversberg dsp->rx_W = (dsp->rx_R + (dsp_poll >> 1))
12048dd2f36fSAndreas Eversberg & CMX_BUFF_MASK;
1205960366cfSKarsten Keil } else {
1206960366cfSKarsten Keil dsp->rx_R = 0;
12078dd2f36fSAndreas Eversberg if (dsp->cmx_delay)
1208960366cfSKarsten Keil dsp->rx_W = dsp->cmx_delay;
12098dd2f36fSAndreas Eversberg else
12108dd2f36fSAndreas Eversberg dsp->rx_W = dsp_poll >> 1;
1211960366cfSKarsten Keil }
1212960366cfSKarsten Keil }
1213960366cfSKarsten Keil /* if frame contains time code, write directly */
1214960366cfSKarsten Keil if (dsp->features.unordered) {
1215960366cfSKarsten Keil dsp->rx_W = (hh->id & CMX_BUFF_MASK);
1216960366cfSKarsten Keil /* printk(KERN_DEBUG "%s %08x\n", dsp->name, hh->id); */
1217960366cfSKarsten Keil }
1218960366cfSKarsten Keil /*
1219960366cfSKarsten Keil * if we underrun (or maybe overrun),
1220960366cfSKarsten Keil * we set our new read pointer, and write silence to buffer
1221960366cfSKarsten Keil */
1222960366cfSKarsten Keil if (((dsp->rx_W-dsp->rx_R) & CMX_BUFF_MASK) >= CMX_BUFF_HALF) {
1223190f71d9SAndreas Eversberg if (dsp_debug & DEBUG_DSP_CLOCK)
1224960366cfSKarsten Keil printk(KERN_DEBUG
1225960366cfSKarsten Keil "cmx_receive(dsp=%lx): UNDERRUN (or overrun the "
1226960366cfSKarsten Keil "maximum delay), adjusting read pointer! "
1227960366cfSKarsten Keil "(inst %s)\n", (u_long)dsp, dsp->name);
12288dd2f36fSAndreas Eversberg /* flush rx buffer and set delay to dsp_poll / 2 */
1229960366cfSKarsten Keil if (dsp->features.unordered) {
1230960366cfSKarsten Keil dsp->rx_R = (hh->id & CMX_BUFF_MASK);
12318dd2f36fSAndreas Eversberg if (dsp->cmx_delay)
1232960366cfSKarsten Keil dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
1233960366cfSKarsten Keil & CMX_BUFF_MASK;
1234f7df0b8dSJulia Lawall else
12358dd2f36fSAndreas Eversberg dsp->rx_W = (dsp->rx_R + (dsp_poll >> 1))
12368dd2f36fSAndreas Eversberg & CMX_BUFF_MASK;
1237960366cfSKarsten Keil } else {
1238960366cfSKarsten Keil dsp->rx_R = 0;
12398dd2f36fSAndreas Eversberg if (dsp->cmx_delay)
1240960366cfSKarsten Keil dsp->rx_W = dsp->cmx_delay;
12418dd2f36fSAndreas Eversberg else
12428dd2f36fSAndreas Eversberg dsp->rx_W = dsp_poll >> 1;
1243960366cfSKarsten Keil }
1244960366cfSKarsten Keil memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff));
1245960366cfSKarsten Keil }
1246960366cfSKarsten Keil /* if we have reached double delay, jump back to middle */
1247960366cfSKarsten Keil if (dsp->cmx_delay)
1248960366cfSKarsten Keil if (((dsp->rx_W - dsp->rx_R) & CMX_BUFF_MASK) >=
1249960366cfSKarsten Keil (dsp->cmx_delay << 1)) {
1250190f71d9SAndreas Eversberg if (dsp_debug & DEBUG_DSP_CLOCK)
1251960366cfSKarsten Keil printk(KERN_DEBUG
1252960366cfSKarsten Keil "cmx_receive(dsp=%lx): OVERRUN (because "
1253960366cfSKarsten Keil "twice the delay is reached), adjusting "
1254960366cfSKarsten Keil "read pointer! (inst %s)\n",
1255960366cfSKarsten Keil (u_long)dsp, dsp->name);
1256960366cfSKarsten Keil /* flush buffer */
1257960366cfSKarsten Keil if (dsp->features.unordered) {
1258960366cfSKarsten Keil dsp->rx_R = (hh->id & CMX_BUFF_MASK);
1259960366cfSKarsten Keil dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
1260960366cfSKarsten Keil & CMX_BUFF_MASK;
1261960366cfSKarsten Keil } else {
1262960366cfSKarsten Keil dsp->rx_R = 0;
1263960366cfSKarsten Keil dsp->rx_W = dsp->cmx_delay;
1264960366cfSKarsten Keil }
1265960366cfSKarsten Keil memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff));
1266960366cfSKarsten Keil }
1267960366cfSKarsten Keil
1268960366cfSKarsten Keil /* show where to write */
1269960366cfSKarsten Keil #ifdef CMX_DEBUG
1270960366cfSKarsten Keil printk(KERN_DEBUG
1271960366cfSKarsten Keil "cmx_receive(dsp=%lx): rx_R(dsp)=%05x rx_W(dsp)=%05x len=%d %s\n",
1272960366cfSKarsten Keil (u_long)dsp, dsp->rx_R, dsp->rx_W, len, dsp->name);
1273960366cfSKarsten Keil #endif
1274960366cfSKarsten Keil
1275960366cfSKarsten Keil /* write data into rx_buffer */
1276960366cfSKarsten Keil p = skb->data;
1277960366cfSKarsten Keil d = dsp->rx_buff;
1278960366cfSKarsten Keil w = dsp->rx_W;
1279960366cfSKarsten Keil i = 0;
1280960366cfSKarsten Keil ii = len;
1281960366cfSKarsten Keil while (i < ii) {
1282960366cfSKarsten Keil d[w++ & CMX_BUFF_MASK] = *p++;
1283960366cfSKarsten Keil i++;
1284960366cfSKarsten Keil }
1285960366cfSKarsten Keil
1286960366cfSKarsten Keil /* increase write-pointer */
1287960366cfSKarsten Keil dsp->rx_W = ((dsp->rx_W + len) & CMX_BUFF_MASK);
128887c5fa1bSAndreas Eversberg #ifdef CMX_DELAY_DEBUG
128987c5fa1bSAndreas Eversberg showdelay(dsp, len, (dsp->rx_W-dsp->rx_R) & CMX_BUFF_MASK);
129087c5fa1bSAndreas Eversberg #endif
1291960366cfSKarsten Keil }
1292960366cfSKarsten Keil
1293960366cfSKarsten Keil
1294960366cfSKarsten Keil /*
1295960366cfSKarsten Keil * send (mixed) audio data to card and control jitter
1296960366cfSKarsten Keil */
1297960366cfSKarsten Keil static void
dsp_cmx_send_member(struct dsp * dsp,int len,s32 * c,int members)1298960366cfSKarsten Keil dsp_cmx_send_member(struct dsp *dsp, int len, s32 *c, int members)
1299960366cfSKarsten Keil {
1300960366cfSKarsten Keil struct dsp_conf *conf = dsp->conf;
1301960366cfSKarsten Keil struct dsp *member, *other;
1302960366cfSKarsten Keil register s32 sample;
1303960366cfSKarsten Keil u8 *d, *p, *q, *o_q;
1304960366cfSKarsten Keil struct sk_buff *nskb, *txskb;
1305960366cfSKarsten Keil int r, rr, t, tt, o_r, o_rr;
1306960366cfSKarsten Keil int preload = 0;
1307960366cfSKarsten Keil struct mISDNhead *hh, *thh;
1308bc138ec4SAndreas Eversberg int tx_data_only = 0;
1309960366cfSKarsten Keil
1310960366cfSKarsten Keil /* don't process if: */
1311960366cfSKarsten Keil if (!dsp->b_active) { /* if not active */
1312960366cfSKarsten Keil dsp->last_tx = 0;
1313960366cfSKarsten Keil return;
1314960366cfSKarsten Keil }
1315bc138ec4SAndreas Eversberg if (((dsp->conf && dsp->conf->hardware) || /* hardware conf */
1316bc138ec4SAndreas Eversberg dsp->echo.hardware) && /* OR hardware echo */
1317960366cfSKarsten Keil dsp->tx_R == dsp->tx_W && /* AND no tx-data */
1318960366cfSKarsten Keil !(dsp->tone.tone && dsp->tone.software)) { /* AND not soft tones */
1319bc138ec4SAndreas Eversberg if (!dsp->tx_data) { /* no tx_data for user space required */
1320960366cfSKarsten Keil dsp->last_tx = 0;
1321960366cfSKarsten Keil return;
1322960366cfSKarsten Keil }
1323bc138ec4SAndreas Eversberg if (dsp->conf && dsp->conf->software && dsp->conf->hardware)
1324bc138ec4SAndreas Eversberg tx_data_only = 1;
132574fa9e5dSAndreas Eversberg if (dsp->echo.software && dsp->echo.hardware)
1326bc138ec4SAndreas Eversberg tx_data_only = 1;
1327bc138ec4SAndreas Eversberg }
1328960366cfSKarsten Keil
1329960366cfSKarsten Keil #ifdef CMX_DEBUG
1330960366cfSKarsten Keil printk(KERN_DEBUG
1331960366cfSKarsten Keil "SEND members=%d dsp=%s, conf=%p, rx_R=%05x rx_W=%05x\n",
1332960366cfSKarsten Keil members, dsp->name, conf, dsp->rx_R, dsp->rx_W);
1333960366cfSKarsten Keil #endif
1334960366cfSKarsten Keil
1335960366cfSKarsten Keil /* preload if we have delay set */
1336960366cfSKarsten Keil if (dsp->cmx_delay && !dsp->last_tx) {
1337960366cfSKarsten Keil preload = len;
1338960366cfSKarsten Keil if (preload < 128)
1339960366cfSKarsten Keil preload = 128;
1340960366cfSKarsten Keil }
1341960366cfSKarsten Keil
1342960366cfSKarsten Keil /* PREPARE RESULT */
1343960366cfSKarsten Keil nskb = mI_alloc_skb(len + preload, GFP_ATOMIC);
1344960366cfSKarsten Keil if (!nskb) {
1345960366cfSKarsten Keil printk(KERN_ERR
1346960366cfSKarsten Keil "FATAL ERROR in mISDN_dsp.o: cannot alloc %d bytes\n",
1347960366cfSKarsten Keil len + preload);
1348960366cfSKarsten Keil return;
1349960366cfSKarsten Keil }
1350960366cfSKarsten Keil hh = mISDN_HEAD_P(nskb);
1351960366cfSKarsten Keil hh->prim = PH_DATA_REQ;
1352960366cfSKarsten Keil hh->id = 0;
1353960366cfSKarsten Keil dsp->last_tx = 1;
1354960366cfSKarsten Keil
1355960366cfSKarsten Keil /* set pointers, indexes and stuff */
1356960366cfSKarsten Keil member = dsp;
1357960366cfSKarsten Keil p = dsp->tx_buff; /* transmit data */
1358960366cfSKarsten Keil q = dsp->rx_buff; /* received data */
1359960366cfSKarsten Keil d = skb_put(nskb, preload + len); /* result */
1360960366cfSKarsten Keil t = dsp->tx_R; /* tx-pointers */
1361960366cfSKarsten Keil tt = dsp->tx_W;
1362960366cfSKarsten Keil r = dsp->rx_R; /* rx-pointers */
1363960366cfSKarsten Keil rr = (r + len) & CMX_BUFF_MASK;
1364960366cfSKarsten Keil
1365960366cfSKarsten Keil /* preload with silence, if required */
1366960366cfSKarsten Keil if (preload) {
1367960366cfSKarsten Keil memset(d, dsp_silence, preload);
1368960366cfSKarsten Keil d += preload;
1369960366cfSKarsten Keil }
1370960366cfSKarsten Keil
1371960366cfSKarsten Keil /* PROCESS TONES/TX-DATA ONLY */
1372960366cfSKarsten Keil if (dsp->tone.tone && dsp->tone.software) {
1373960366cfSKarsten Keil /* -> copy tone */
1374960366cfSKarsten Keil dsp_tone_copy(dsp, d, len);
1375960366cfSKarsten Keil dsp->tx_R = 0; /* clear tx buffer */
1376960366cfSKarsten Keil dsp->tx_W = 0;
1377960366cfSKarsten Keil goto send_packet;
1378960366cfSKarsten Keil }
1379960366cfSKarsten Keil /* if we have tx-data but do not use mixing */
1380960366cfSKarsten Keil if (!dsp->tx_mix && t != tt) {
1381960366cfSKarsten Keil /* -> send tx-data and continue when not enough */
1382960366cfSKarsten Keil #ifdef CMX_TX_DEBUG
1383960366cfSKarsten Keil sprintf(debugbuf, "TX sending (%04x-%04x)%p: ", t, tt, p);
1384960366cfSKarsten Keil #endif
1385960366cfSKarsten Keil while (r != rr && t != tt) {
1386960366cfSKarsten Keil #ifdef CMX_TX_DEBUG
1387960366cfSKarsten Keil if (strlen(debugbuf) < 48)
1388eac74af9SKarsten Keil sprintf(debugbuf + strlen(debugbuf), " %02x",
1389eac74af9SKarsten Keil p[t]);
1390960366cfSKarsten Keil #endif
1391960366cfSKarsten Keil *d++ = p[t]; /* write tx_buff */
1392960366cfSKarsten Keil t = (t + 1) & CMX_BUFF_MASK;
1393960366cfSKarsten Keil r = (r + 1) & CMX_BUFF_MASK;
1394960366cfSKarsten Keil }
1395960366cfSKarsten Keil if (r == rr) {
1396960366cfSKarsten Keil dsp->tx_R = t;
1397960366cfSKarsten Keil #ifdef CMX_TX_DEBUG
1398960366cfSKarsten Keil printk(KERN_DEBUG "%s\n", debugbuf);
1399960366cfSKarsten Keil #endif
1400960366cfSKarsten Keil goto send_packet;
1401960366cfSKarsten Keil }
1402960366cfSKarsten Keil }
1403960366cfSKarsten Keil #ifdef CMX_TX_DEBUG
1404960366cfSKarsten Keil printk(KERN_DEBUG "%s\n", debugbuf);
1405960366cfSKarsten Keil #endif
1406960366cfSKarsten Keil
1407960366cfSKarsten Keil /* PROCESS DATA (one member / no conf) */
1408960366cfSKarsten Keil if (!conf || members <= 1) {
1409960366cfSKarsten Keil /* -> if echo is NOT enabled */
1410bc138ec4SAndreas Eversberg if (!dsp->echo.software) {
1411960366cfSKarsten Keil /* -> send tx-data if available or use 0-volume */
1412960366cfSKarsten Keil while (r != rr && t != tt) {
1413960366cfSKarsten Keil *d++ = p[t]; /* write tx_buff */
1414960366cfSKarsten Keil t = (t + 1) & CMX_BUFF_MASK;
1415960366cfSKarsten Keil r = (r + 1) & CMX_BUFF_MASK;
1416960366cfSKarsten Keil }
14178dd2f36fSAndreas Eversberg if (r != rr) {
1418190f71d9SAndreas Eversberg if (dsp_debug & DEBUG_DSP_CLOCK)
1419190f71d9SAndreas Eversberg printk(KERN_DEBUG "%s: RX empty\n",
14208dd2f36fSAndreas Eversberg __func__);
1421960366cfSKarsten Keil memset(d, dsp_silence, (rr - r) & CMX_BUFF_MASK);
14228dd2f36fSAndreas Eversberg }
1423960366cfSKarsten Keil /* -> if echo is enabled */
1424960366cfSKarsten Keil } else {
1425960366cfSKarsten Keil /*
1426960366cfSKarsten Keil * -> mix tx-data with echo if available,
1427960366cfSKarsten Keil * or use echo only
1428960366cfSKarsten Keil */
1429960366cfSKarsten Keil while (r != rr && t != tt) {
1430960366cfSKarsten Keil *d++ = dsp_audio_mix_law[(p[t] << 8) | q[r]];
1431960366cfSKarsten Keil t = (t + 1) & CMX_BUFF_MASK;
1432960366cfSKarsten Keil r = (r + 1) & CMX_BUFF_MASK;
1433960366cfSKarsten Keil }
1434960366cfSKarsten Keil while (r != rr) {
1435960366cfSKarsten Keil *d++ = q[r]; /* echo */
1436960366cfSKarsten Keil r = (r + 1) & CMX_BUFF_MASK;
1437960366cfSKarsten Keil }
1438960366cfSKarsten Keil }
1439960366cfSKarsten Keil dsp->tx_R = t;
1440960366cfSKarsten Keil goto send_packet;
1441960366cfSKarsten Keil }
1442960366cfSKarsten Keil /* PROCESS DATA (two members) */
1443960366cfSKarsten Keil #ifdef CMX_CONF_DEBUG
1444960366cfSKarsten Keil if (0) {
1445960366cfSKarsten Keil #else
1446960366cfSKarsten Keil if (members == 2) {
1447960366cfSKarsten Keil #endif
1448960366cfSKarsten Keil /* "other" becomes other party */
1449960366cfSKarsten Keil other = (list_entry(conf->mlist.next,
1450960366cfSKarsten Keil struct dsp_conf_member, list))->dsp;
1451960366cfSKarsten Keil if (other == member)
1452960366cfSKarsten Keil other = (list_entry(conf->mlist.prev,
1453960366cfSKarsten Keil struct dsp_conf_member, list))->dsp;
1454960366cfSKarsten Keil o_q = other->rx_buff; /* received data */
1455960366cfSKarsten Keil o_rr = (other->rx_R + len) & CMX_BUFF_MASK;
1456960366cfSKarsten Keil /* end of rx-pointer */
1457960366cfSKarsten Keil o_r = (o_rr - rr + r) & CMX_BUFF_MASK;
1458960366cfSKarsten Keil /* start rx-pointer at current read position*/
1459960366cfSKarsten Keil /* -> if echo is NOT enabled */
1460bc138ec4SAndreas Eversberg if (!dsp->echo.software) {
1461960366cfSKarsten Keil /*
1462960366cfSKarsten Keil * -> copy other member's rx-data,
1463960366cfSKarsten Keil * if tx-data is available, mix
1464960366cfSKarsten Keil */
1465960366cfSKarsten Keil while (o_r != o_rr && t != tt) {
1466960366cfSKarsten Keil *d++ = dsp_audio_mix_law[(p[t] << 8) | o_q[o_r]];
1467960366cfSKarsten Keil t = (t + 1) & CMX_BUFF_MASK;
1468960366cfSKarsten Keil o_r = (o_r + 1) & CMX_BUFF_MASK;
1469960366cfSKarsten Keil }
1470960366cfSKarsten Keil while (o_r != o_rr) {
1471960366cfSKarsten Keil *d++ = o_q[o_r];
1472960366cfSKarsten Keil o_r = (o_r + 1) & CMX_BUFF_MASK;
1473960366cfSKarsten Keil }
1474960366cfSKarsten Keil /* -> if echo is enabled */
1475960366cfSKarsten Keil } else {
1476960366cfSKarsten Keil /*
1477960366cfSKarsten Keil * -> mix other member's rx-data with echo,
1478960366cfSKarsten Keil * if tx-data is available, mix
1479960366cfSKarsten Keil */
1480960366cfSKarsten Keil while (r != rr && t != tt) {
1481960366cfSKarsten Keil sample = dsp_audio_law_to_s32[p[t]] +
1482960366cfSKarsten Keil dsp_audio_law_to_s32[q[r]] +
1483960366cfSKarsten Keil dsp_audio_law_to_s32[o_q[o_r]];
1484960366cfSKarsten Keil if (sample < -32768)
1485960366cfSKarsten Keil sample = -32768;
1486960366cfSKarsten Keil else if (sample > 32767)
1487960366cfSKarsten Keil sample = 32767;
1488960366cfSKarsten Keil *d++ = dsp_audio_s16_to_law[sample & 0xffff];
1489960366cfSKarsten Keil /* tx-data + rx_data + echo */
1490960366cfSKarsten Keil t = (t + 1) & CMX_BUFF_MASK;
1491960366cfSKarsten Keil r = (r + 1) & CMX_BUFF_MASK;
1492960366cfSKarsten Keil o_r = (o_r + 1) & CMX_BUFF_MASK;
1493960366cfSKarsten Keil }
1494960366cfSKarsten Keil while (r != rr) {
1495960366cfSKarsten Keil *d++ = dsp_audio_mix_law[(q[r] << 8) | o_q[o_r]];
1496960366cfSKarsten Keil r = (r + 1) & CMX_BUFF_MASK;
1497960366cfSKarsten Keil o_r = (o_r + 1) & CMX_BUFF_MASK;
1498960366cfSKarsten Keil }
1499960366cfSKarsten Keil }
1500960366cfSKarsten Keil dsp->tx_R = t;
1501960366cfSKarsten Keil goto send_packet;
1502960366cfSKarsten Keil }
1503960366cfSKarsten Keil /* PROCESS DATA (three or more members) */
1504960366cfSKarsten Keil /* -> if echo is NOT enabled */
1505bc138ec4SAndreas Eversberg if (!dsp->echo.software) {
1506960366cfSKarsten Keil /*
150725985edcSLucas De Marchi * -> subtract rx-data from conf-data,
1508960366cfSKarsten Keil * if tx-data is available, mix
1509960366cfSKarsten Keil */
1510960366cfSKarsten Keil while (r != rr && t != tt) {
1511960366cfSKarsten Keil sample = dsp_audio_law_to_s32[p[t]] + *c++ -
1512960366cfSKarsten Keil dsp_audio_law_to_s32[q[r]];
1513960366cfSKarsten Keil if (sample < -32768)
1514960366cfSKarsten Keil sample = -32768;
1515960366cfSKarsten Keil else if (sample > 32767)
1516960366cfSKarsten Keil sample = 32767;
1517960366cfSKarsten Keil *d++ = dsp_audio_s16_to_law[sample & 0xffff];
1518960366cfSKarsten Keil /* conf-rx+tx */
1519960366cfSKarsten Keil r = (r + 1) & CMX_BUFF_MASK;
1520960366cfSKarsten Keil t = (t + 1) & CMX_BUFF_MASK;
1521960366cfSKarsten Keil }
1522960366cfSKarsten Keil while (r != rr) {
1523960366cfSKarsten Keil sample = *c++ - dsp_audio_law_to_s32[q[r]];
1524960366cfSKarsten Keil if (sample < -32768)
1525960366cfSKarsten Keil sample = -32768;
1526960366cfSKarsten Keil else if (sample > 32767)
1527960366cfSKarsten Keil sample = 32767;
1528960366cfSKarsten Keil *d++ = dsp_audio_s16_to_law[sample & 0xffff];
1529960366cfSKarsten Keil /* conf-rx */
1530960366cfSKarsten Keil r = (r + 1) & CMX_BUFF_MASK;
1531960366cfSKarsten Keil }
1532960366cfSKarsten Keil /* -> if echo is enabled */
1533960366cfSKarsten Keil } else {
1534960366cfSKarsten Keil /*
1535960366cfSKarsten Keil * -> encode conf-data, if tx-data
1536960366cfSKarsten Keil * is available, mix
1537960366cfSKarsten Keil */
1538960366cfSKarsten Keil while (r != rr && t != tt) {
1539960366cfSKarsten Keil sample = dsp_audio_law_to_s32[p[t]] + *c++;
1540960366cfSKarsten Keil if (sample < -32768)
1541960366cfSKarsten Keil sample = -32768;
1542960366cfSKarsten Keil else if (sample > 32767)
1543960366cfSKarsten Keil sample = 32767;
1544960366cfSKarsten Keil *d++ = dsp_audio_s16_to_law[sample & 0xffff];
1545960366cfSKarsten Keil /* conf(echo)+tx */
1546960366cfSKarsten Keil t = (t + 1) & CMX_BUFF_MASK;
1547960366cfSKarsten Keil r = (r + 1) & CMX_BUFF_MASK;
1548960366cfSKarsten Keil }
1549960366cfSKarsten Keil while (r != rr) {
1550960366cfSKarsten Keil sample = *c++;
1551960366cfSKarsten Keil if (sample < -32768)
1552960366cfSKarsten Keil sample = -32768;
1553960366cfSKarsten Keil else if (sample > 32767)
1554960366cfSKarsten Keil sample = 32767;
1555960366cfSKarsten Keil *d++ = dsp_audio_s16_to_law[sample & 0xffff];
1556960366cfSKarsten Keil /* conf(echo) */
1557960366cfSKarsten Keil r = (r + 1) & CMX_BUFF_MASK;
1558960366cfSKarsten Keil }
1559960366cfSKarsten Keil }
1560960366cfSKarsten Keil dsp->tx_R = t;
1561960366cfSKarsten Keil goto send_packet;
1562960366cfSKarsten Keil
1563960366cfSKarsten Keil send_packet:
1564960366cfSKarsten Keil /*
1565960366cfSKarsten Keil * send tx-data if enabled - don't filter,
156625985edcSLucas De Marchi * because we want what we send, not what we filtered
1567960366cfSKarsten Keil */
1568960366cfSKarsten Keil if (dsp->tx_data) {
1569bc138ec4SAndreas Eversberg if (tx_data_only) {
1570bc138ec4SAndreas Eversberg hh->prim = DL_DATA_REQ;
1571bc138ec4SAndreas Eversberg hh->id = 0;
1572bc138ec4SAndreas Eversberg /* queue and trigger */
1573bc138ec4SAndreas Eversberg skb_queue_tail(&dsp->sendq, nskb);
1574bc138ec4SAndreas Eversberg schedule_work(&dsp->workq);
1575bc138ec4SAndreas Eversberg /* exit because only tx_data is used */
1576bc138ec4SAndreas Eversberg return;
1577bc138ec4SAndreas Eversberg } else {
1578960366cfSKarsten Keil txskb = mI_alloc_skb(len, GFP_ATOMIC);
1579960366cfSKarsten Keil if (!txskb) {
1580960366cfSKarsten Keil printk(KERN_ERR
1581960366cfSKarsten Keil "FATAL ERROR in mISDN_dsp.o: "
1582960366cfSKarsten Keil "cannot alloc %d bytes\n", len);
1583960366cfSKarsten Keil } else {
1584960366cfSKarsten Keil thh = mISDN_HEAD_P(txskb);
1585960366cfSKarsten Keil thh->prim = DL_DATA_REQ;
1586960366cfSKarsten Keil thh->id = 0;
158759ae1d12SJohannes Berg skb_put_data(txskb, nskb->data + preload, len);
1588960366cfSKarsten Keil /* queue (trigger later) */
1589960366cfSKarsten Keil skb_queue_tail(&dsp->sendq, txskb);
1590960366cfSKarsten Keil }
1591960366cfSKarsten Keil }
1592bc138ec4SAndreas Eversberg }
1593bc138ec4SAndreas Eversberg
1594bc138ec4SAndreas Eversberg /* send data only to card, if we don't just calculated tx_data */
1595960366cfSKarsten Keil /* adjust volume */
1596960366cfSKarsten Keil if (dsp->tx_volume)
1597960366cfSKarsten Keil dsp_change_volume(nskb, dsp->tx_volume);
1598960366cfSKarsten Keil /* pipeline */
1599960366cfSKarsten Keil if (dsp->pipeline.inuse)
1600bc138ec4SAndreas Eversberg dsp_pipeline_process_tx(&dsp->pipeline, nskb->data,
1601bc138ec4SAndreas Eversberg nskb->len);
1602960366cfSKarsten Keil /* crypt */
1603960366cfSKarsten Keil if (dsp->bf_enable)
1604960366cfSKarsten Keil dsp_bf_encrypt(dsp, nskb->data, nskb->len);
1605960366cfSKarsten Keil /* queue and trigger */
1606960366cfSKarsten Keil skb_queue_tail(&dsp->sendq, nskb);
1607960366cfSKarsten Keil schedule_work(&dsp->workq);
1608960366cfSKarsten Keil }
1609960366cfSKarsten Keil
1610fae3e7fbSKarsten Keil static u32 jittercount; /* counter for jitter check */
1611960366cfSKarsten Keil struct timer_list dsp_spl_tl;
16129cf6ace5SKarsten Keil unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
16133bd69ad1SAndreas Eversberg static u16 dsp_count; /* last sample count */
16143bd69ad1SAndreas Eversberg static int dsp_count_valid; /* if we have last sample count */
1615960366cfSKarsten Keil
1616960366cfSKarsten Keil void
16171696ec86SNathan Chancellor dsp_cmx_send(struct timer_list *arg)
1618960366cfSKarsten Keil {
1619960366cfSKarsten Keil struct dsp_conf *conf;
1620960366cfSKarsten Keil struct dsp_conf_member *member;
1621960366cfSKarsten Keil struct dsp *dsp;
1622960366cfSKarsten Keil int mustmix, members;
162344e09589SFrank Seidel static s32 mixbuffer[MAX_POLL + 100];
162444e09589SFrank Seidel s32 *c;
1625960366cfSKarsten Keil u8 *p, *q;
1626960366cfSKarsten Keil int r, rr;
1627960366cfSKarsten Keil int jittercheck = 0, delay, i;
1628960366cfSKarsten Keil u_long flags;
16293bd69ad1SAndreas Eversberg u16 length, count;
1630960366cfSKarsten Keil
1631960366cfSKarsten Keil /* lock */
1632960366cfSKarsten Keil spin_lock_irqsave(&dsp_lock, flags);
1633960366cfSKarsten Keil
16343bd69ad1SAndreas Eversberg if (!dsp_count_valid) {
16353bd69ad1SAndreas Eversberg dsp_count = mISDN_clock_get();
1636960366cfSKarsten Keil length = dsp_poll;
16373bd69ad1SAndreas Eversberg dsp_count_valid = 1;
1638960366cfSKarsten Keil } else {
16393bd69ad1SAndreas Eversberg count = mISDN_clock_get();
16403bd69ad1SAndreas Eversberg length = count - dsp_count;
16413bd69ad1SAndreas Eversberg dsp_count = count;
1642960366cfSKarsten Keil }
1643960366cfSKarsten Keil if (length > MAX_POLL + 100)
1644960366cfSKarsten Keil length = MAX_POLL + 100;
16453bd69ad1SAndreas Eversberg /* printk(KERN_DEBUG "len=%d dsp_count=0x%x\n", length, dsp_count); */
1646960366cfSKarsten Keil
1647960366cfSKarsten Keil /*
16483bd69ad1SAndreas Eversberg * check if jitter needs to be checked (this is every second)
1649960366cfSKarsten Keil */
16503bd69ad1SAndreas Eversberg jittercount += length;
16513bd69ad1SAndreas Eversberg if (jittercount >= 8000) {
16523bd69ad1SAndreas Eversberg jittercount -= 8000;
1653960366cfSKarsten Keil jittercheck = 1;
16543bd69ad1SAndreas Eversberg }
1655960366cfSKarsten Keil
1656960366cfSKarsten Keil /* loop all members that do not require conference mixing */
1657960366cfSKarsten Keil list_for_each_entry(dsp, &dsp_ilist, list) {
1658960366cfSKarsten Keil if (dsp->hdlc)
1659960366cfSKarsten Keil continue;
1660960366cfSKarsten Keil conf = dsp->conf;
1661960366cfSKarsten Keil mustmix = 0;
1662960366cfSKarsten Keil members = 0;
1663960366cfSKarsten Keil if (conf) {
1664e0807c43SChristophe JAILLET members = list_count_nodes(&conf->mlist);
1665960366cfSKarsten Keil #ifdef CMX_CONF_DEBUG
1666960366cfSKarsten Keil if (conf->software && members > 1)
1667960366cfSKarsten Keil #else
1668960366cfSKarsten Keil if (conf->software && members > 2)
1669960366cfSKarsten Keil #endif
1670960366cfSKarsten Keil mustmix = 1;
1671960366cfSKarsten Keil }
1672960366cfSKarsten Keil
1673960366cfSKarsten Keil /* transmission required */
1674960366cfSKarsten Keil if (!mustmix) {
1675960366cfSKarsten Keil dsp_cmx_send_member(dsp, length, mixbuffer, members);
1676960366cfSKarsten Keil
1677960366cfSKarsten Keil /*
1678960366cfSKarsten Keil * unused mixbuffer is given to prevent a
1679960366cfSKarsten Keil * potential null-pointer-bug
1680960366cfSKarsten Keil */
1681960366cfSKarsten Keil }
1682960366cfSKarsten Keil }
1683960366cfSKarsten Keil
1684960366cfSKarsten Keil /* loop all members that require conference mixing */
1685960366cfSKarsten Keil list_for_each_entry(conf, &conf_ilist, list) {
1686960366cfSKarsten Keil /* count members and check hardware */
1687e0807c43SChristophe JAILLET members = list_count_nodes(&conf->mlist);
1688960366cfSKarsten Keil #ifdef CMX_CONF_DEBUG
1689960366cfSKarsten Keil if (conf->software && members > 1) {
1690960366cfSKarsten Keil #else
1691960366cfSKarsten Keil if (conf->software && members > 2) {
1692960366cfSKarsten Keil #endif
1693960366cfSKarsten Keil /* check for hdlc conf */
1694960366cfSKarsten Keil member = list_entry(conf->mlist.next,
1695960366cfSKarsten Keil struct dsp_conf_member, list);
1696960366cfSKarsten Keil if (member->dsp->hdlc)
1697960366cfSKarsten Keil continue;
1698960366cfSKarsten Keil /* mix all data */
1699960366cfSKarsten Keil memset(mixbuffer, 0, length * sizeof(s32));
1700960366cfSKarsten Keil list_for_each_entry(member, &conf->mlist, list) {
1701960366cfSKarsten Keil dsp = member->dsp;
1702960366cfSKarsten Keil /* get range of data to mix */
1703960366cfSKarsten Keil c = mixbuffer;
1704960366cfSKarsten Keil q = dsp->rx_buff;
1705960366cfSKarsten Keil r = dsp->rx_R;
1706960366cfSKarsten Keil rr = (r + length) & CMX_BUFF_MASK;
1707960366cfSKarsten Keil /* add member's data */
1708960366cfSKarsten Keil while (r != rr) {
1709960366cfSKarsten Keil *c++ += dsp_audio_law_to_s32[q[r]];
1710960366cfSKarsten Keil r = (r + 1) & CMX_BUFF_MASK;
1711960366cfSKarsten Keil }
1712960366cfSKarsten Keil }
1713960366cfSKarsten Keil
1714960366cfSKarsten Keil /* process each member */
1715960366cfSKarsten Keil list_for_each_entry(member, &conf->mlist, list) {
1716960366cfSKarsten Keil /* transmission */
1717960366cfSKarsten Keil dsp_cmx_send_member(member->dsp, length,
1718960366cfSKarsten Keil mixbuffer, members);
1719960366cfSKarsten Keil }
1720960366cfSKarsten Keil }
1721960366cfSKarsten Keil }
1722960366cfSKarsten Keil
1723960366cfSKarsten Keil /* delete rx-data, increment buffers, change pointers */
1724960366cfSKarsten Keil list_for_each_entry(dsp, &dsp_ilist, list) {
1725960366cfSKarsten Keil if (dsp->hdlc)
1726960366cfSKarsten Keil continue;
1727960366cfSKarsten Keil p = dsp->rx_buff;
1728960366cfSKarsten Keil q = dsp->tx_buff;
1729960366cfSKarsten Keil r = dsp->rx_R;
1730960366cfSKarsten Keil /* move receive pointer when receiving */
1731960366cfSKarsten Keil if (!dsp->rx_is_off) {
1732960366cfSKarsten Keil rr = (r + length) & CMX_BUFF_MASK;
1733960366cfSKarsten Keil /* delete rx-data */
1734960366cfSKarsten Keil while (r != rr) {
1735960366cfSKarsten Keil p[r] = dsp_silence;
1736960366cfSKarsten Keil r = (r + 1) & CMX_BUFF_MASK;
1737960366cfSKarsten Keil }
1738960366cfSKarsten Keil /* increment rx-buffer pointer */
1739960366cfSKarsten Keil dsp->rx_R = r; /* write incremented read pointer */
1740960366cfSKarsten Keil }
1741960366cfSKarsten Keil
1742960366cfSKarsten Keil /* check current rx_delay */
1743960366cfSKarsten Keil delay = (dsp->rx_W-dsp->rx_R) & CMX_BUFF_MASK;
1744960366cfSKarsten Keil if (delay >= CMX_BUFF_HALF)
1745960366cfSKarsten Keil delay = 0; /* will be the delay before next write */
1746960366cfSKarsten Keil /* check for lower delay */
1747960366cfSKarsten Keil if (delay < dsp->rx_delay[0])
1748960366cfSKarsten Keil dsp->rx_delay[0] = delay;
1749960366cfSKarsten Keil /* check current tx_delay */
1750960366cfSKarsten Keil delay = (dsp->tx_W-dsp->tx_R) & CMX_BUFF_MASK;
1751960366cfSKarsten Keil if (delay >= CMX_BUFF_HALF)
1752960366cfSKarsten Keil delay = 0; /* will be the delay before next write */
1753960366cfSKarsten Keil /* check for lower delay */
1754960366cfSKarsten Keil if (delay < dsp->tx_delay[0])
1755960366cfSKarsten Keil dsp->tx_delay[0] = delay;
1756960366cfSKarsten Keil if (jittercheck) {
1757960366cfSKarsten Keil /* find the lowest of all rx_delays */
1758960366cfSKarsten Keil delay = dsp->rx_delay[0];
1759960366cfSKarsten Keil i = 1;
1760960366cfSKarsten Keil while (i < MAX_SECONDS_JITTER_CHECK) {
1761960366cfSKarsten Keil if (delay > dsp->rx_delay[i])
1762960366cfSKarsten Keil delay = dsp->rx_delay[i];
1763960366cfSKarsten Keil i++;
1764960366cfSKarsten Keil }
1765960366cfSKarsten Keil /*
1766960366cfSKarsten Keil * remove rx_delay only if we have delay AND we
17678dd2f36fSAndreas Eversberg * have not preset cmx_delay AND
17688dd2f36fSAndreas Eversberg * the delay is greater dsp_poll
1769960366cfSKarsten Keil */
17708dd2f36fSAndreas Eversberg if (delay > dsp_poll && !dsp->cmx_delay) {
1771190f71d9SAndreas Eversberg if (dsp_debug & DEBUG_DSP_CLOCK)
1772960366cfSKarsten Keil printk(KERN_DEBUG
1773960366cfSKarsten Keil "%s lowest rx_delay of %d bytes for"
1774960366cfSKarsten Keil " dsp %s are now removed.\n",
1775960366cfSKarsten Keil __func__, delay,
1776960366cfSKarsten Keil dsp->name);
1777960366cfSKarsten Keil r = dsp->rx_R;
17788dd2f36fSAndreas Eversberg rr = (r + delay - (dsp_poll >> 1))
17798dd2f36fSAndreas Eversberg & CMX_BUFF_MASK;
1780960366cfSKarsten Keil /* delete rx-data */
1781960366cfSKarsten Keil while (r != rr) {
1782960366cfSKarsten Keil p[r] = dsp_silence;
1783960366cfSKarsten Keil r = (r + 1) & CMX_BUFF_MASK;
1784960366cfSKarsten Keil }
1785960366cfSKarsten Keil /* increment rx-buffer pointer */
1786960366cfSKarsten Keil dsp->rx_R = r;
1787960366cfSKarsten Keil /* write incremented read pointer */
1788960366cfSKarsten Keil }
1789960366cfSKarsten Keil /* find the lowest of all tx_delays */
1790960366cfSKarsten Keil delay = dsp->tx_delay[0];
1791960366cfSKarsten Keil i = 1;
1792960366cfSKarsten Keil while (i < MAX_SECONDS_JITTER_CHECK) {
1793960366cfSKarsten Keil if (delay > dsp->tx_delay[i])
1794960366cfSKarsten Keil delay = dsp->tx_delay[i];
1795960366cfSKarsten Keil i++;
1796960366cfSKarsten Keil }
1797960366cfSKarsten Keil /*
1798960366cfSKarsten Keil * remove delay only if we have delay AND we
1799960366cfSKarsten Keil * have enabled tx_dejitter
1800960366cfSKarsten Keil */
18018dd2f36fSAndreas Eversberg if (delay > dsp_poll && dsp->tx_dejitter) {
1802190f71d9SAndreas Eversberg if (dsp_debug & DEBUG_DSP_CLOCK)
1803960366cfSKarsten Keil printk(KERN_DEBUG
1804960366cfSKarsten Keil "%s lowest tx_delay of %d bytes for"
1805960366cfSKarsten Keil " dsp %s are now removed.\n",
1806960366cfSKarsten Keil __func__, delay,
1807960366cfSKarsten Keil dsp->name);
1808960366cfSKarsten Keil r = dsp->tx_R;
18098dd2f36fSAndreas Eversberg rr = (r + delay - (dsp_poll >> 1))
18108dd2f36fSAndreas Eversberg & CMX_BUFF_MASK;
1811960366cfSKarsten Keil /* delete tx-data */
1812960366cfSKarsten Keil while (r != rr) {
1813960366cfSKarsten Keil q[r] = dsp_silence;
1814960366cfSKarsten Keil r = (r + 1) & CMX_BUFF_MASK;
1815960366cfSKarsten Keil }
1816960366cfSKarsten Keil /* increment rx-buffer pointer */
1817960366cfSKarsten Keil dsp->tx_R = r;
1818960366cfSKarsten Keil /* write incremented read pointer */
1819960366cfSKarsten Keil }
1820960366cfSKarsten Keil /* scroll up delays */
1821960366cfSKarsten Keil i = MAX_SECONDS_JITTER_CHECK - 1;
1822960366cfSKarsten Keil while (i) {
1823960366cfSKarsten Keil dsp->rx_delay[i] = dsp->rx_delay[i - 1];
1824960366cfSKarsten Keil dsp->tx_delay[i] = dsp->tx_delay[i - 1];
1825960366cfSKarsten Keil i--;
1826960366cfSKarsten Keil }
1827960366cfSKarsten Keil dsp->tx_delay[0] = CMX_BUFF_HALF; /* (infinite) delay */
1828960366cfSKarsten Keil dsp->rx_delay[0] = CMX_BUFF_HALF; /* (infinite) delay */
1829960366cfSKarsten Keil }
1830960366cfSKarsten Keil }
1831960366cfSKarsten Keil
1832960366cfSKarsten Keil /* if next event would be in the past ... */
1833960366cfSKarsten Keil if ((s32)(dsp_spl_jiffies + dsp_tics-jiffies) <= 0)
1834960366cfSKarsten Keil dsp_spl_jiffies = jiffies + 1;
1835960366cfSKarsten Keil else
1836960366cfSKarsten Keil dsp_spl_jiffies += dsp_tics;
1837960366cfSKarsten Keil
1838960366cfSKarsten Keil dsp_spl_tl.expires = dsp_spl_jiffies;
1839960366cfSKarsten Keil add_timer(&dsp_spl_tl);
1840960366cfSKarsten Keil
1841960366cfSKarsten Keil /* unlock */
1842960366cfSKarsten Keil spin_unlock_irqrestore(&dsp_lock, flags);
1843960366cfSKarsten Keil }
1844960366cfSKarsten Keil
1845960366cfSKarsten Keil /*
1846960366cfSKarsten Keil * audio data is transmitted from upper layer to the dsp
1847960366cfSKarsten Keil */
1848960366cfSKarsten Keil void
1849960366cfSKarsten Keil dsp_cmx_transmit(struct dsp *dsp, struct sk_buff *skb)
1850960366cfSKarsten Keil {
1851960366cfSKarsten Keil u_int w, ww;
1852960366cfSKarsten Keil u8 *d, *p;
1853960366cfSKarsten Keil int space; /* todo: , l = skb->len; */
1854960366cfSKarsten Keil #ifdef CMX_TX_DEBUG
1855960366cfSKarsten Keil char debugbuf[256] = "";
1856960366cfSKarsten Keil #endif
1857960366cfSKarsten Keil
1858960366cfSKarsten Keil /* check if there is enough space, and then copy */
1859960366cfSKarsten Keil w = dsp->tx_W;
1860960366cfSKarsten Keil ww = dsp->tx_R;
1861960366cfSKarsten Keil p = dsp->tx_buff;
1862960366cfSKarsten Keil d = skb->data;
18638dd2f36fSAndreas Eversberg space = (ww - w - 1) & CMX_BUFF_MASK;
1864960366cfSKarsten Keil /* write-pointer should not overrun nor reach read pointer */
18658dd2f36fSAndreas Eversberg if (space < skb->len) {
1866960366cfSKarsten Keil /* write to the space we have left */
18678dd2f36fSAndreas Eversberg ww = (ww - 1) & CMX_BUFF_MASK; /* end one byte prior tx_R */
1868190f71d9SAndreas Eversberg if (dsp_debug & DEBUG_DSP_CLOCK)
18690aafe75dSPeter Schlaile printk(KERN_DEBUG "%s: TX overflow space=%d skb->len="
18700aafe75dSPeter Schlaile "%d, w=0x%04x, ww=0x%04x\n", __func__, space,
18710aafe75dSPeter Schlaile skb->len, w, ww);
18728dd2f36fSAndreas Eversberg } else
1873960366cfSKarsten Keil /* write until all byte are copied */
1874960366cfSKarsten Keil ww = (w + skb->len) & CMX_BUFF_MASK;
1875960366cfSKarsten Keil dsp->tx_W = ww;
1876960366cfSKarsten Keil /* show current buffer */
1877960366cfSKarsten Keil #ifdef CMX_DEBUG
1878960366cfSKarsten Keil printk(KERN_DEBUG
1879960366cfSKarsten Keil "cmx_transmit(dsp=%lx) %d bytes to 0x%x-0x%x. %s\n",
1880960366cfSKarsten Keil (u_long)dsp, (ww - w) & CMX_BUFF_MASK, w, ww, dsp->name);
1881960366cfSKarsten Keil #endif
1882960366cfSKarsten Keil
1883960366cfSKarsten Keil /* copy transmit data to tx-buffer */
1884960366cfSKarsten Keil #ifdef CMX_TX_DEBUG
1885960366cfSKarsten Keil sprintf(debugbuf, "TX getting (%04x-%04x)%p: ", w, ww, p);
1886960366cfSKarsten Keil #endif
1887960366cfSKarsten Keil while (w != ww) {
1888960366cfSKarsten Keil #ifdef CMX_TX_DEBUG
1889960366cfSKarsten Keil if (strlen(debugbuf) < 48)
1890960366cfSKarsten Keil sprintf(debugbuf + strlen(debugbuf), " %02x", *d);
1891960366cfSKarsten Keil #endif
1892960366cfSKarsten Keil p[w] = *d++;
1893960366cfSKarsten Keil w = (w + 1) & CMX_BUFF_MASK;
1894960366cfSKarsten Keil }
1895960366cfSKarsten Keil #ifdef CMX_TX_DEBUG
1896960366cfSKarsten Keil printk(KERN_DEBUG "%s\n", debugbuf);
1897960366cfSKarsten Keil #endif
1898960366cfSKarsten Keil
1899960366cfSKarsten Keil }
1900960366cfSKarsten Keil
1901960366cfSKarsten Keil /*
1902960366cfSKarsten Keil * hdlc data is received from card and sent to all members.
1903960366cfSKarsten Keil */
1904960366cfSKarsten Keil void
1905960366cfSKarsten Keil dsp_cmx_hdlc(struct dsp *dsp, struct sk_buff *skb)
1906960366cfSKarsten Keil {
1907960366cfSKarsten Keil struct sk_buff *nskb = NULL;
1908960366cfSKarsten Keil struct dsp_conf_member *member;
1909960366cfSKarsten Keil struct mISDNhead *hh;
1910960366cfSKarsten Keil
1911960366cfSKarsten Keil /* not if not active */
1912960366cfSKarsten Keil if (!dsp->b_active)
1913960366cfSKarsten Keil return;
1914960366cfSKarsten Keil
1915960366cfSKarsten Keil /* check if we have sompen */
1916960366cfSKarsten Keil if (skb->len < 1)
1917960366cfSKarsten Keil return;
1918960366cfSKarsten Keil
1919960366cfSKarsten Keil /* no conf */
1920960366cfSKarsten Keil if (!dsp->conf) {
1921bc138ec4SAndreas Eversberg /* in case of software echo */
1922bc138ec4SAndreas Eversberg if (dsp->echo.software) {
1923960366cfSKarsten Keil nskb = skb_clone(skb, GFP_ATOMIC);
1924960366cfSKarsten Keil if (nskb) {
1925960366cfSKarsten Keil hh = mISDN_HEAD_P(nskb);
1926960366cfSKarsten Keil hh->prim = PH_DATA_REQ;
1927960366cfSKarsten Keil hh->id = 0;
1928960366cfSKarsten Keil skb_queue_tail(&dsp->sendq, nskb);
1929960366cfSKarsten Keil schedule_work(&dsp->workq);
1930960366cfSKarsten Keil }
1931f27b8c35SIlpo Järvinen }
1932960366cfSKarsten Keil return;
1933960366cfSKarsten Keil }
1934960366cfSKarsten Keil /* in case of hardware conference */
1935960366cfSKarsten Keil if (dsp->conf->hardware)
1936960366cfSKarsten Keil return;
1937960366cfSKarsten Keil list_for_each_entry(member, &dsp->conf->mlist, list) {
1938bc138ec4SAndreas Eversberg if (dsp->echo.software || member->dsp != dsp) {
1939960366cfSKarsten Keil nskb = skb_clone(skb, GFP_ATOMIC);
1940960366cfSKarsten Keil if (nskb) {
1941960366cfSKarsten Keil hh = mISDN_HEAD_P(nskb);
1942960366cfSKarsten Keil hh->prim = PH_DATA_REQ;
1943960366cfSKarsten Keil hh->id = 0;
1944960366cfSKarsten Keil skb_queue_tail(&member->dsp->sendq, nskb);
1945960366cfSKarsten Keil schedule_work(&member->dsp->workq);
1946960366cfSKarsten Keil }
1947960366cfSKarsten Keil }
1948960366cfSKarsten Keil }
1949960366cfSKarsten Keil }
1950