dsp_cmx.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902
  1. /*
  2. * Audio crossconnecting/conferrencing (hardware level).
  3. *
  4. * Copyright 2002 by Andreas Eversberg (jolly@eversberg.eu)
  5. *
  6. * This software may be used and distributed according to the terms
  7. * of the GNU General Public License, incorporated herein by reference.
  8. *
  9. */
  10. /*
  11. * The process of adding and removing parties to/from a conference:
  12. *
  13. * There is a chain of struct dsp_conf which has one or more members in a chain
  14. * of struct dsp_conf_member.
  15. *
  16. * After a party is added, the conference is checked for hardware capability.
  17. * Also if a party is removed, the conference is checked again.
  18. *
  19. * There are 3 different solutions: -1 = software, 0 = hardware-crossconnect
  20. * 1-n = hardware-conference. The n will give the conference number.
  21. *
  22. * Depending on the change after removal or insertion of a party, hardware
  23. * commands are given.
  24. *
  25. * The current solution is stored within the struct dsp_conf entry.
  26. */
  27. /*
  28. * HOW THE CMX WORKS:
  29. *
  30. * There are 3 types of interaction: One member is alone, in this case only
  31. * data flow from upper to lower layer is done.
  32. * Two members will also exchange their data so they are crossconnected.
  33. * Three or more members will be added in a conference and will hear each
  34. * other but will not receive their own speech (echo) if not enabled.
  35. *
  36. * Features of CMX are:
  37. * - Crossconnecting or even conference, if more than two members are together.
  38. * - Force mixing of transmit data with other crossconnect/conference members.
  39. * - Echo generation to benchmark the delay of audio processing.
  40. * - Use hardware to minimize cpu load, disable FIFO load and minimize delay.
  41. * - Dejittering and clock generation.
  42. *
  43. * There are 2 buffers:
  44. *
  45. *
  46. * RX-Buffer
  47. * R W
  48. * | |
  49. * ----------------+-------------+-------------------
  50. *
  51. * The rx-buffer is a ring buffer used to store the received data for each
  52. * individual member. This is only the case if data needs to be dejittered
  53. * or in case of a conference where different clocks require reclocking.
  54. * The transmit-clock (R) will read the buffer.
  55. * If the clock overruns the write-pointer, we will have a buffer underrun.
  56. * If the write pointer always has a certain distance from the transmit-
  57. * clock, we will have a delay. The delay will dynamically be increased and
  58. * reduced.
  59. *
  60. *
  61. * TX-Buffer
  62. * R W
  63. * | |
  64. * -----------------+--------+-----------------------
  65. *
  66. * The tx-buffer is a ring buffer to queue the transmit data from user space
  67. * until it will be mixed or sent. There are two pointers, R and W. If the write
  68. * pointer W would reach or overrun R, the buffer would overrun. In this case
  69. * (some) data is dropped so that it will not overrun.
  70. * Additionally a dynamic dejittering can be enabled. this allows data from
  71. * user space that have jitter and different clock source.
  72. *
  73. *
  74. * Clock:
  75. *
  76. * A Clock is not required, if the data source has exactly one clock. In this
  77. * case the data source is forwarded to the destination.
  78. *
  79. * A Clock is required, because the data source
  80. * - has multiple clocks.
  81. * - has no usable clock due to jitter or packet loss (VoIP).
  82. * In this case the system's clock is used. The clock resolution depends on
  83. * the jiffie resolution.
  84. *
  85. * If a member joins a conference:
  86. *
  87. * - If a member joins, its rx_buff is set to silence and change read pointer
  88. * to transmit clock.
  89. *
  90. * The procedure of received data from card is explained in cmx_receive.
  91. * The procedure of received data from user space is explained in cmx_transmit.
  92. * The procedure of transmit data to card is cmx_send.
  93. *
  94. *
  95. * Interaction with other features:
  96. *
  97. * DTMF:
  98. * DTMF decoding is done before the data is crossconnected.
  99. *
  100. * Volume change:
  101. * Changing rx-volume is done before the data is crossconnected. The tx-volume
  102. * must be changed whenever data is transmitted to the card by the cmx.
  103. *
  104. * Tones:
  105. * If a tone is enabled, it will be processed whenever data is transmitted to
  106. * the card. It will replace the tx-data from the user space.
  107. * If tones are generated by hardware, this conference member is removed for
  108. * this time.
  109. *
  110. * Disable rx-data:
  111. * If cmx is realized in hardware, rx data will be disabled if requested by
  112. * the upper layer. If dtmf decoding is done by software and enabled, rx data
  113. * will not be diabled but blocked to the upper layer.
  114. *
  115. * HFC conference engine:
  116. * If it is possible to realize all features using hardware, hardware will be
  117. * used if not forbidden by control command. Disabling rx-data provides
  118. * absolutely traffic free audio processing. (except for the quick 1-frame
  119. * upload of a tone loop, only once for a new tone)
  120. *
  121. */
  122. /* delay.h is required for hw_lock.h */
  123. #include <linux/delay.h>
  124. #include <linux/mISDNif.h>
  125. #include <linux/mISDNdsp.h>
  126. #include "core.h"
  127. #include "dsp.h"
  128. /*
  129. * debugging of multi party conference,
  130. * by using conference even with two members
  131. */
  132. /* #define CMX_CONF_DEBUG */
  133. /*#define CMX_DEBUG * massive read/write pointer output */
  134. /*#define CMX_TX_DEBUG * massive read/write on tx-buffer with content */
  135. static inline int
  136. count_list_member(struct list_head *head)
  137. {
  138. int cnt = 0;
  139. struct list_head *m;
  140. list_for_each(m, head)
  141. cnt++;
  142. return cnt;
  143. }
  144. /*
  145. * debug cmx memory structure
  146. */
  147. void
  148. dsp_cmx_debug(struct dsp *dsp)
  149. {
  150. struct dsp_conf *conf;
  151. struct dsp_conf_member *member;
  152. struct dsp *odsp;
  153. printk(KERN_DEBUG "-----Current DSP\n");
  154. list_for_each_entry(odsp, &dsp_ilist, list) {
  155. printk(KERN_DEBUG "* %s echo=%d txmix=%d",
  156. odsp->name, odsp->echo, odsp->tx_mix);
  157. if (odsp->conf)
  158. printk(" (Conf %d)", odsp->conf->id);
  159. if (dsp == odsp)
  160. printk(" *this*");
  161. printk("\n");
  162. }
  163. printk(KERN_DEBUG "-----Current Conf:\n");
  164. list_for_each_entry(conf, &conf_ilist, list) {
  165. printk(KERN_DEBUG "* Conf %d (%p)\n", conf->id, conf);
  166. list_for_each_entry(member, &conf->mlist, list) {
  167. printk(KERN_DEBUG
  168. " - member = %s (slot_tx %d, bank_tx %d, "
  169. "slot_rx %d, bank_rx %d hfc_conf %d)%s\n",
  170. member->dsp->name, member->dsp->pcm_slot_tx,
  171. member->dsp->pcm_bank_tx, member->dsp->pcm_slot_rx,
  172. member->dsp->pcm_bank_rx, member->dsp->hfc_conf,
  173. (member->dsp == dsp) ? " *this*" : "");
  174. }
  175. }
  176. printk(KERN_DEBUG "-----end\n");
  177. }
  178. /*
  179. * search conference
  180. */
  181. static struct dsp_conf *
  182. dsp_cmx_search_conf(u32 id)
  183. {
  184. struct dsp_conf *conf;
  185. if (!id) {
  186. printk(KERN_WARNING "%s: conference ID is 0.\n", __func__);
  187. return NULL;
  188. }
  189. /* search conference */
  190. list_for_each_entry(conf, &conf_ilist, list)
  191. if (conf->id == id)
  192. return conf;
  193. return NULL;
  194. }
  195. /*
  196. * add member to conference
  197. */
  198. static int
  199. dsp_cmx_add_conf_member(struct dsp *dsp, struct dsp_conf *conf)
  200. {
  201. struct dsp_conf_member *member;
  202. if (!conf || !dsp) {
  203. printk(KERN_WARNING "%s: conf or dsp is 0.\n", __func__);
  204. return -EINVAL;
  205. }
  206. if (dsp->member) {
  207. printk(KERN_WARNING "%s: dsp is already member in a conf.\n",
  208. __func__);
  209. return -EINVAL;
  210. }
  211. if (dsp->conf) {
  212. printk(KERN_WARNING "%s: dsp is already in a conf.\n",
  213. __func__);
  214. return -EINVAL;
  215. }
  216. member = kzalloc(sizeof(struct dsp_conf_member), GFP_ATOMIC);
  217. if (!member) {
  218. printk(KERN_ERR "kmalloc struct dsp_conf_member failed\n");
  219. return -ENOMEM;
  220. }
  221. member->dsp = dsp;
  222. /* clear rx buffer */
  223. memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff));
  224. dsp->rx_init = 1; /* rx_W and rx_R will be adjusted on first frame */
  225. dsp->rx_W = 0;
  226. dsp->rx_R = 0;
  227. list_add_tail(&member->list, &conf->mlist);
  228. dsp->conf = conf;
  229. dsp->member = member;
  230. return 0;
  231. }
  232. /*
  233. * del member from conference
  234. */
  235. int
  236. dsp_cmx_del_conf_member(struct dsp *dsp)
  237. {
  238. struct dsp_conf_member *member;
  239. if (!dsp) {
  240. printk(KERN_WARNING "%s: dsp is 0.\n",
  241. __func__);
  242. return -EINVAL;
  243. }
  244. if (!dsp->conf) {
  245. printk(KERN_WARNING "%s: dsp is not in a conf.\n",
  246. __func__);
  247. return -EINVAL;
  248. }
  249. if (list_empty(&dsp->conf->mlist)) {
  250. printk(KERN_WARNING "%s: dsp has linked an empty conf.\n",
  251. __func__);
  252. return -EINVAL;
  253. }
  254. /* find us in conf */
  255. list_for_each_entry(member, &dsp->conf->mlist, list) {
  256. if (member->dsp == dsp) {
  257. list_del(&member->list);
  258. dsp->conf = NULL;
  259. dsp->member = NULL;
  260. kfree(member);
  261. return 0;
  262. }
  263. }
  264. printk(KERN_WARNING
  265. "%s: dsp is not present in its own conf_meber list.\n",
  266. __func__);
  267. return -EINVAL;
  268. }
  269. /*
  270. * new conference
  271. */
  272. static struct dsp_conf
  273. *dsp_cmx_new_conf(u32 id)
  274. {
  275. struct dsp_conf *conf;
  276. if (!id) {
  277. printk(KERN_WARNING "%s: id is 0.\n",
  278. __func__);
  279. return NULL;
  280. }
  281. conf = kzalloc(sizeof(struct dsp_conf), GFP_ATOMIC);
  282. if (!conf) {
  283. printk(KERN_ERR "kmalloc struct dsp_conf failed\n");
  284. return NULL;
  285. }
  286. INIT_LIST_HEAD(&conf->mlist);
  287. conf->id = id;
  288. list_add_tail(&conf->list, &conf_ilist);
  289. return conf;
  290. }
  291. /*
  292. * del conference
  293. */
  294. int
  295. dsp_cmx_del_conf(struct dsp_conf *conf)
  296. {
  297. if (!conf) {
  298. printk(KERN_WARNING "%s: conf is null.\n",
  299. __func__);
  300. return -EINVAL;
  301. }
  302. if (!list_empty(&conf->mlist)) {
  303. printk(KERN_WARNING "%s: conf not empty.\n",
  304. __func__);
  305. return -EINVAL;
  306. }
  307. list_del(&conf->list);
  308. kfree(conf);
  309. return 0;
  310. }
  311. /*
  312. * send HW message to hfc card
  313. */
  314. static void
  315. dsp_cmx_hw_message(struct dsp *dsp, u32 message, u32 param1, u32 param2,
  316. u32 param3, u32 param4)
  317. {
  318. struct mISDN_ctrl_req cq;
  319. memset(&cq, 0, sizeof(cq));
  320. cq.op = message;
  321. cq.p1 = param1 | (param2 << 8);
  322. cq.p2 = param3 | (param4 << 8);
  323. if (dsp->ch.peer)
  324. dsp->ch.peer->ctrl(dsp->ch.peer, CONTROL_CHANNEL, &cq);
  325. }
  326. /*
  327. * do hardware update and set the software/hardware flag
  328. *
  329. * either a conference or a dsp instance can be given
  330. * if only dsp instance is given, the instance is not associated with a conf
  331. * and therefore removed. if a conference is given, the dsp is expected to
  332. * be member of that conference.
  333. */
  334. void
  335. dsp_cmx_hardware(struct dsp_conf *conf, struct dsp *dsp)
  336. {
  337. struct dsp_conf_member *member, *nextm;
  338. struct dsp *finddsp;
  339. int memb = 0, i, ii, i1, i2;
  340. int freeunits[8];
  341. u_char freeslots[256];
  342. int same_hfc = -1, same_pcm = -1, current_conf = -1,
  343. all_conf = 1;
  344. /* dsp gets updated (no conf) */
  345. if (!conf) {
  346. if (!dsp)
  347. return;
  348. if (dsp_debug & DEBUG_DSP_CMX)
  349. printk(KERN_DEBUG "%s checking dsp %s\n",
  350. __func__, dsp->name);
  351. one_member:
  352. /* remove HFC conference if enabled */
  353. if (dsp->hfc_conf >= 0) {
  354. if (dsp_debug & DEBUG_DSP_CMX)
  355. printk(KERN_DEBUG
  356. "%s removing %s from HFC conf %d "
  357. "because dsp is split\n", __func__,
  358. dsp->name, dsp->hfc_conf);
  359. dsp_cmx_hw_message(dsp, MISDN_CTRL_HFC_CONF_SPLIT,
  360. 0, 0, 0, 0);
  361. dsp->hfc_conf = -1;
  362. }
  363. /* process hw echo */
  364. if (dsp->features.pcm_banks < 1)
  365. return;
  366. if (!dsp->echo) {
  367. /* NO ECHO: remove PCM slot if assigned */
  368. if (dsp->pcm_slot_tx >= 0 || dsp->pcm_slot_rx >= 0) {
  369. if (dsp_debug & DEBUG_DSP_CMX)
  370. printk(KERN_DEBUG "%s removing %s from"
  371. " PCM slot %d (TX) %d (RX) because"
  372. " dsp is split (no echo)\n",
  373. __func__, dsp->name,
  374. dsp->pcm_slot_tx, dsp->pcm_slot_rx);
  375. dsp_cmx_hw_message(dsp, MISDN_CTRL_HFC_PCM_DISC,
  376. 0, 0, 0, 0);
  377. dsp->pcm_slot_tx = -1;
  378. dsp->pcm_bank_tx = -1;
  379. dsp->pcm_slot_rx = -1;
  380. dsp->pcm_bank_rx = -1;
  381. }
  382. return;
  383. }
  384. /* ECHO: already echo */
  385. if (dsp->pcm_slot_tx >= 0 && dsp->pcm_slot_rx < 0 &&
  386. dsp->pcm_bank_tx == 2 && dsp->pcm_bank_rx == 2)
  387. return;
  388. /* ECHO: if slot already assigned */
  389. if (dsp->pcm_slot_tx >= 0) {
  390. dsp->pcm_slot_rx = dsp->pcm_slot_tx;
  391. dsp->pcm_bank_tx = 2; /* 2 means loop */
  392. dsp->pcm_bank_rx = 2;
  393. if (dsp_debug & DEBUG_DSP_CMX)
  394. printk(KERN_DEBUG
  395. "%s refresh %s for echo using slot %d\n",
  396. __func__, dsp->name,
  397. dsp->pcm_slot_tx);
  398. dsp_cmx_hw_message(dsp, MISDN_CTRL_HFC_PCM_CONN,
  399. dsp->pcm_slot_tx, 2, dsp->pcm_slot_rx, 2);
  400. return;
  401. }
  402. /* ECHO: find slot */
  403. dsp->pcm_slot_tx = -1;
  404. dsp->pcm_slot_rx = -1;
  405. memset(freeslots, 1, sizeof(freeslots));
  406. list_for_each_entry(finddsp, &dsp_ilist, list) {
  407. if (finddsp->features.pcm_id == dsp->features.pcm_id) {
  408. if (finddsp->pcm_slot_rx >= 0 &&
  409. finddsp->pcm_slot_rx < sizeof(freeslots))
  410. freeslots[finddsp->pcm_slot_rx] = 0;
  411. if (finddsp->pcm_slot_tx >= 0 &&
  412. finddsp->pcm_slot_tx < sizeof(freeslots))
  413. freeslots[finddsp->pcm_slot_tx] = 0;
  414. }
  415. }
  416. i = 0;
  417. ii = dsp->features.pcm_slots;
  418. while (i < ii) {
  419. if (freeslots[i])
  420. break;
  421. i++;
  422. }
  423. if (i == ii) {
  424. if (dsp_debug & DEBUG_DSP_CMX)
  425. printk(KERN_DEBUG
  426. "%s no slot available for echo\n",
  427. __func__);
  428. /* no more slots available */
  429. return;
  430. }
  431. /* assign free slot */
  432. dsp->pcm_slot_tx = i;
  433. dsp->pcm_slot_rx = i;
  434. dsp->pcm_bank_tx = 2; /* loop */
  435. dsp->pcm_bank_rx = 2;
  436. if (dsp_debug & DEBUG_DSP_CMX)
  437. printk(KERN_DEBUG
  438. "%s assign echo for %s using slot %d\n",
  439. __func__, dsp->name, dsp->pcm_slot_tx);
  440. dsp_cmx_hw_message(dsp, MISDN_CTRL_HFC_PCM_CONN,
  441. dsp->pcm_slot_tx, 2, dsp->pcm_slot_rx, 2);
  442. return;
  443. }
  444. /* conf gets updated (all members) */
  445. if (dsp_debug & DEBUG_DSP_CMX)
  446. printk(KERN_DEBUG "%s checking conference %d\n",
  447. __func__, conf->id);
  448. if (list_empty(&conf->mlist)) {
  449. printk(KERN_ERR "%s: conference whithout members\n",
  450. __func__);
  451. return;
  452. }
  453. member = list_entry(conf->mlist.next, struct dsp_conf_member, list);
  454. same_hfc = member->dsp->features.hfc_id;
  455. same_pcm = member->dsp->features.pcm_id;
  456. /* check all members in our conference */
  457. list_for_each_entry(member, &conf->mlist, list) {
  458. /* check if member uses mixing */
  459. if (member->dsp->tx_mix) {
  460. if (dsp_debug & DEBUG_DSP_CMX)
  461. printk(KERN_DEBUG
  462. "%s dsp %s cannot form a conf, because "
  463. "tx_mix is turned on\n", __func__,
  464. member->dsp->name);
  465. conf_software:
  466. list_for_each_entry(member, &conf->mlist, list) {
  467. dsp = member->dsp;
  468. /* remove HFC conference if enabled */
  469. if (dsp->hfc_conf >= 0) {
  470. if (dsp_debug & DEBUG_DSP_CMX)
  471. printk(KERN_DEBUG
  472. "%s removing %s from HFC "
  473. "conf %d because not "
  474. "possible with hardware\n",
  475. __func__,
  476. dsp->name,
  477. dsp->hfc_conf);
  478. dsp_cmx_hw_message(dsp,
  479. MISDN_CTRL_HFC_CONF_SPLIT,
  480. 0, 0, 0, 0);
  481. dsp->hfc_conf = -1;
  482. }
  483. /* remove PCM slot if assigned */
  484. if (dsp->pcm_slot_tx >= 0 ||
  485. dsp->pcm_slot_rx >= 0) {
  486. if (dsp_debug & DEBUG_DSP_CMX)
  487. printk(KERN_DEBUG "%s removing "
  488. "%s from PCM slot %d (TX)"
  489. " slot %d (RX) because not"
  490. " possible with hardware\n",
  491. __func__,
  492. dsp->name,
  493. dsp->pcm_slot_tx,
  494. dsp->pcm_slot_rx);
  495. dsp_cmx_hw_message(dsp,
  496. MISDN_CTRL_HFC_PCM_DISC,
  497. 0, 0, 0, 0);
  498. dsp->pcm_slot_tx = -1;
  499. dsp->pcm_bank_tx = -1;
  500. dsp->pcm_slot_rx = -1;
  501. dsp->pcm_bank_rx = -1;
  502. }
  503. }
  504. conf->hardware = 0;
  505. conf->software = 1;
  506. return;
  507. }
  508. /* check if member has echo turned on */
  509. if (member->dsp->echo) {
  510. if (dsp_debug & DEBUG_DSP_CMX)
  511. printk(KERN_DEBUG
  512. "%s dsp %s cannot form a conf, because "
  513. "echo is turned on\n", __func__,
  514. member->dsp->name);
  515. goto conf_software;
  516. }
  517. /* check if member has tx_mix turned on */
  518. if (member->dsp->tx_mix) {
  519. if (dsp_debug & DEBUG_DSP_CMX)
  520. printk(KERN_DEBUG
  521. "%s dsp %s cannot form a conf, because "
  522. "tx_mix is turned on\n",
  523. __func__, member->dsp->name);
  524. goto conf_software;
  525. }
  526. /* check if member changes volume at an not suppoted level */
  527. if (member->dsp->tx_volume) {
  528. if (dsp_debug & DEBUG_DSP_CMX)
  529. printk(KERN_DEBUG
  530. "%s dsp %s cannot form a conf, because "
  531. "tx_volume is changed\n",
  532. __func__, member->dsp->name);
  533. goto conf_software;
  534. }
  535. if (member->dsp->rx_volume) {
  536. if (dsp_debug & DEBUG_DSP_CMX)
  537. printk(KERN_DEBUG
  538. "%s dsp %s cannot form a conf, because "
  539. "rx_volume is changed\n",
  540. __func__, member->dsp->name);
  541. goto conf_software;
  542. }
  543. /* check if tx-data turned on */
  544. if (member->dsp->tx_data) {
  545. if (dsp_debug & DEBUG_DSP_CMX)
  546. printk(KERN_DEBUG
  547. "%s dsp %s cannot form a conf, because "
  548. "tx_data is turned on\n",
  549. __func__, member->dsp->name);
  550. goto conf_software;
  551. }
  552. /* check if pipeline exists */
  553. if (member->dsp->pipeline.inuse) {
  554. if (dsp_debug & DEBUG_DSP_CMX)
  555. printk(KERN_DEBUG
  556. "%s dsp %s cannot form a conf, because "
  557. "pipeline exists\n", __func__,
  558. member->dsp->name);
  559. goto conf_software;
  560. }
  561. /* check if encryption is enabled */
  562. if (member->dsp->bf_enable) {
  563. if (dsp_debug & DEBUG_DSP_CMX)
  564. printk(KERN_DEBUG "%s dsp %s cannot form a "
  565. "conf, because encryption is enabled\n",
  566. __func__, member->dsp->name);
  567. goto conf_software;
  568. }
  569. /* check if member is on a card with PCM support */
  570. if (member->dsp->features.pcm_id < 0) {
  571. if (dsp_debug & DEBUG_DSP_CMX)
  572. printk(KERN_DEBUG
  573. "%s dsp %s cannot form a conf, because "
  574. "dsp has no PCM bus\n",
  575. __func__, member->dsp->name);
  576. goto conf_software;
  577. }
  578. /* check if relations are on the same PCM bus */
  579. if (member->dsp->features.pcm_id != same_pcm) {
  580. if (dsp_debug & DEBUG_DSP_CMX)
  581. printk(KERN_DEBUG
  582. "%s dsp %s cannot form a conf, because "
  583. "dsp is on a different PCM bus than the "
  584. "first dsp\n",
  585. __func__, member->dsp->name);
  586. goto conf_software;
  587. }
  588. /* determine if members are on the same hfc chip */
  589. if (same_hfc != member->dsp->features.hfc_id)
  590. same_hfc = -1;
  591. /* if there are members already in a conference */
  592. if (current_conf < 0 && member->dsp->hfc_conf >= 0)
  593. current_conf = member->dsp->hfc_conf;
  594. /* if any member is not in a conference */
  595. if (member->dsp->hfc_conf < 0)
  596. all_conf = 0;
  597. memb++;
  598. }
  599. /* if no member, this is an error */
  600. if (memb < 1)
  601. return;
  602. /* one member */
  603. if (memb == 1) {
  604. if (dsp_debug & DEBUG_DSP_CMX)
  605. printk(KERN_DEBUG
  606. "%s conf %d cannot form a HW conference, "
  607. "because dsp is alone\n", __func__, conf->id);
  608. conf->hardware = 0;
  609. conf->software = 0;
  610. member = list_entry(conf->mlist.next, struct dsp_conf_member,
  611. list);
  612. dsp = member->dsp;
  613. goto one_member;
  614. }
  615. /*
  616. * ok, now we are sure that all members are on the same pcm.
  617. * now we will see if we have only two members, so we can do
  618. * crossconnections, which don't have any limitations.
  619. */
  620. /* if we have only two members */
  621. if (memb == 2) {
  622. member = list_entry(conf->mlist.next, struct dsp_conf_member,
  623. list);
  624. nextm = list_entry(member->list.next, struct dsp_conf_member,
  625. list);
  626. /* remove HFC conference if enabled */
  627. if (member->dsp->hfc_conf >= 0) {
  628. if (dsp_debug & DEBUG_DSP_CMX)
  629. printk(KERN_DEBUG
  630. "%s removing %s from HFC conf %d because "
  631. "two parties require only a PCM slot\n",
  632. __func__, member->dsp->name,
  633. member->dsp->hfc_conf);
  634. dsp_cmx_hw_message(member->dsp,
  635. MISDN_CTRL_HFC_CONF_SPLIT, 0, 0, 0, 0);
  636. member->dsp->hfc_conf = -1;
  637. }
  638. if (nextm->dsp->hfc_conf >= 0) {
  639. if (dsp_debug & DEBUG_DSP_CMX)
  640. printk(KERN_DEBUG
  641. "%s removing %s from HFC conf %d because "
  642. "two parties require only a PCM slot\n",
  643. __func__, nextm->dsp->name,
  644. nextm->dsp->hfc_conf);
  645. dsp_cmx_hw_message(nextm->dsp,
  646. MISDN_CTRL_HFC_CONF_SPLIT, 0, 0, 0, 0);
  647. nextm->dsp->hfc_conf = -1;
  648. }
  649. /* if members have two banks (and not on the same chip) */
  650. if (member->dsp->features.pcm_banks > 1 &&
  651. nextm->dsp->features.pcm_banks > 1 &&
  652. member->dsp->features.hfc_id !=
  653. nextm->dsp->features.hfc_id) {
  654. /* if both members have same slots with crossed banks */
  655. if (member->dsp->pcm_slot_tx >= 0 &&
  656. member->dsp->pcm_slot_rx >= 0 &&
  657. nextm->dsp->pcm_slot_tx >= 0 &&
  658. nextm->dsp->pcm_slot_rx >= 0 &&
  659. nextm->dsp->pcm_slot_tx ==
  660. member->dsp->pcm_slot_rx &&
  661. nextm->dsp->pcm_slot_rx ==
  662. member->dsp->pcm_slot_tx &&
  663. nextm->dsp->pcm_slot_tx ==
  664. member->dsp->pcm_slot_tx &&
  665. member->dsp->pcm_bank_tx !=
  666. member->dsp->pcm_bank_rx &&
  667. nextm->dsp->pcm_bank_tx !=
  668. nextm->dsp->pcm_bank_rx) {
  669. /* all members have same slot */
  670. if (dsp_debug & DEBUG_DSP_CMX)
  671. printk(KERN_DEBUG
  672. "%s dsp %s & %s stay joined on "
  673. "PCM slot %d bank %d (TX) bank %d "
  674. "(RX) (on different chips)\n",
  675. __func__,
  676. member->dsp->name,
  677. nextm->dsp->name,
  678. member->dsp->pcm_slot_tx,
  679. member->dsp->pcm_bank_tx,
  680. member->dsp->pcm_bank_rx);
  681. conf->hardware = 0;
  682. conf->software = 1;
  683. return;
  684. }
  685. /* find a new slot */
  686. memset(freeslots, 1, sizeof(freeslots));
  687. list_for_each_entry(dsp, &dsp_ilist, list) {
  688. if (dsp != member->dsp &&
  689. dsp != nextm->dsp &&
  690. member->dsp->features.pcm_id ==
  691. dsp->features.pcm_id) {
  692. if (dsp->pcm_slot_rx >= 0 &&
  693. dsp->pcm_slot_rx <
  694. sizeof(freeslots))
  695. freeslots[dsp->pcm_slot_rx] = 0;
  696. if (dsp->pcm_slot_tx >= 0 &&
  697. dsp->pcm_slot_tx <
  698. sizeof(freeslots))
  699. freeslots[dsp->pcm_slot_tx] = 0;
  700. }
  701. }
  702. i = 0;
  703. ii = member->dsp->features.pcm_slots;
  704. while (i < ii) {
  705. if (freeslots[i])
  706. break;
  707. i++;
  708. }
  709. if (i == ii) {
  710. if (dsp_debug & DEBUG_DSP_CMX)
  711. printk(KERN_DEBUG
  712. "%s no slot available for "
  713. "%s & %s\n", __func__,
  714. member->dsp->name,
  715. nextm->dsp->name);
  716. /* no more slots available */
  717. goto conf_software;
  718. }
  719. /* assign free slot */
  720. member->dsp->pcm_slot_tx = i;
  721. member->dsp->pcm_slot_rx = i;
  722. nextm->dsp->pcm_slot_tx = i;
  723. nextm->dsp->pcm_slot_rx = i;
  724. member->dsp->pcm_bank_rx = 0;
  725. member->dsp->pcm_bank_tx = 1;
  726. nextm->dsp->pcm_bank_rx = 1;
  727. nextm->dsp->pcm_bank_tx = 0;
  728. if (dsp_debug & DEBUG_DSP_CMX)
  729. printk(KERN_DEBUG
  730. "%s adding %s & %s to new PCM slot %d "
  731. "(TX and RX on different chips) because "
  732. "both members have not same slots\n",
  733. __func__,
  734. member->dsp->name,
  735. nextm->dsp->name,
  736. member->dsp->pcm_slot_tx);
  737. dsp_cmx_hw_message(member->dsp, MISDN_CTRL_HFC_PCM_CONN,
  738. member->dsp->pcm_slot_tx, member->dsp->pcm_bank_tx,
  739. member->dsp->pcm_slot_rx, member->dsp->pcm_bank_rx);
  740. dsp_cmx_hw_message(nextm->dsp, MISDN_CTRL_HFC_PCM_CONN,
  741. nextm->dsp->pcm_slot_tx, nextm->dsp->pcm_bank_tx,
  742. nextm->dsp->pcm_slot_rx, nextm->dsp->pcm_bank_rx);
  743. conf->hardware = 1;
  744. conf->software = 0;
  745. return;
  746. /* if members have one bank (or on the same chip) */
  747. } else {
  748. /* if both members have different crossed slots */
  749. if (member->dsp->pcm_slot_tx >= 0 &&
  750. member->dsp->pcm_slot_rx >= 0 &&
  751. nextm->dsp->pcm_slot_tx >= 0 &&
  752. nextm->dsp->pcm_slot_rx >= 0 &&
  753. nextm->dsp->pcm_slot_tx ==
  754. member->dsp->pcm_slot_rx &&
  755. nextm->dsp->pcm_slot_rx ==
  756. member->dsp->pcm_slot_tx &&
  757. member->dsp->pcm_slot_tx !=
  758. member->dsp->pcm_slot_rx &&
  759. member->dsp->pcm_bank_tx == 0 &&
  760. member->dsp->pcm_bank_rx == 0 &&
  761. nextm->dsp->pcm_bank_tx == 0 &&
  762. nextm->dsp->pcm_bank_rx == 0) {
  763. /* all members have same slot */
  764. if (dsp_debug & DEBUG_DSP_CMX)
  765. printk(KERN_DEBUG
  766. "%s dsp %s & %s stay joined on PCM "
  767. "slot %d (TX) %d (RX) on same chip "
  768. "or one bank PCM)\n", __func__,
  769. member->dsp->name,
  770. nextm->dsp->name,
  771. member->dsp->pcm_slot_tx,
  772. member->dsp->pcm_slot_rx);
  773. conf->hardware = 0;
  774. conf->software = 1;
  775. return;
  776. }
  777. /* find two new slot */
  778. memset(freeslots, 1, sizeof(freeslots));
  779. list_for_each_entry(dsp, &dsp_ilist, list) {
  780. if (dsp != member->dsp &&
  781. dsp != nextm->dsp &&
  782. member->dsp->features.pcm_id ==
  783. dsp->features.pcm_id) {
  784. if (dsp->pcm_slot_rx >= 0 &&
  785. dsp->pcm_slot_rx <
  786. sizeof(freeslots))
  787. freeslots[dsp->pcm_slot_rx] = 0;
  788. if (dsp->pcm_slot_tx >= 0 &&
  789. dsp->pcm_slot_tx <
  790. sizeof(freeslots))
  791. freeslots[dsp->pcm_slot_tx] = 0;
  792. }
  793. }
  794. i1 = 0;
  795. ii = member->dsp->features.pcm_slots;
  796. while (i1 < ii) {
  797. if (freeslots[i1])
  798. break;
  799. i1++;
  800. }
  801. if (i1 == ii) {
  802. if (dsp_debug & DEBUG_DSP_CMX)
  803. printk(KERN_DEBUG
  804. "%s no slot available "
  805. "for %s & %s\n", __func__,
  806. member->dsp->name,
  807. nextm->dsp->name);
  808. /* no more slots available */
  809. goto conf_software;
  810. }
  811. i2 = i1+1;
  812. while (i2 < ii) {
  813. if (freeslots[i2])
  814. break;
  815. i2++;
  816. }
  817. if (i2 == ii) {
  818. if (dsp_debug & DEBUG_DSP_CMX)
  819. printk(KERN_DEBUG
  820. "%s no slot available "
  821. "for %s & %s\n",
  822. __func__,
  823. member->dsp->name,
  824. nextm->dsp->name);
  825. /* no more slots available */
  826. goto conf_software;
  827. }
  828. /* assign free slots */
  829. member->dsp->pcm_slot_tx = i1;
  830. member->dsp->pcm_slot_rx = i2;
  831. nextm->dsp->pcm_slot_tx = i2;
  832. nextm->dsp->pcm_slot_rx = i1;
  833. member->dsp->pcm_bank_rx = 0;
  834. member->dsp->pcm_bank_tx = 0;
  835. nextm->dsp->pcm_bank_rx = 0;
  836. nextm->dsp->pcm_bank_tx = 0;
  837. if (dsp_debug & DEBUG_DSP_CMX)
  838. printk(KERN_DEBUG
  839. "%s adding %s & %s to new PCM slot %d "
  840. "(TX) %d (RX) on same chip or one bank "
  841. "PCM, because both members have not "
  842. "crossed slots\n", __func__,
  843. member->dsp->name,
  844. nextm->dsp->name,
  845. member->dsp->pcm_slot_tx,
  846. member->dsp->pcm_slot_rx);
  847. dsp_cmx_hw_message(member->dsp, MISDN_CTRL_HFC_PCM_CONN,
  848. member->dsp->pcm_slot_tx, member->dsp->pcm_bank_tx,
  849. member->dsp->pcm_slot_rx, member->dsp->pcm_bank_rx);
  850. dsp_cmx_hw_message(nextm->dsp, MISDN_CTRL_HFC_PCM_CONN,
  851. nextm->dsp->pcm_slot_tx, nextm->dsp->pcm_bank_tx,
  852. nextm->dsp->pcm_slot_rx, nextm->dsp->pcm_bank_rx);
  853. conf->hardware = 1;
  854. conf->software = 0;
  855. return;
  856. }
  857. }
  858. /*
  859. * if we have more than two, we may check if we have a conference
  860. * unit available on the chip. also all members must be on the same
  861. */
  862. /* if not the same HFC chip */
  863. if (same_hfc < 0) {
  864. if (dsp_debug & DEBUG_DSP_CMX)
  865. printk(KERN_DEBUG
  866. "%s conference %d cannot be formed, because "
  867. "members are on different chips or not "
  868. "on HFC chip\n",
  869. __func__, conf->id);
  870. goto conf_software;
  871. }
  872. /* for more than two members.. */
  873. /* in case of hdlc, we change to software */
  874. if (dsp->hdlc)
  875. goto conf_software;
  876. /* if all members already have the same conference */
  877. if (all_conf)
  878. return;
  879. /*
  880. * if there is an existing conference, but not all members have joined
  881. */
  882. if (current_conf >= 0) {
  883. join_members:
  884. list_for_each_entry(member, &conf->mlist, list) {
  885. /* join to current conference */
  886. if (member->dsp->hfc_conf == current_conf)
  887. continue;
  888. /* get a free timeslot first */
  889. memset(freeslots, 1, sizeof(freeslots));
  890. list_for_each_entry(dsp, &dsp_ilist, list) {
  891. /*
  892. * not checking current member, because
  893. * slot will be overwritten.
  894. */
  895. if (
  896. dsp != member->dsp &&
  897. /* dsp must be on the same PCM */
  898. member->dsp->features.pcm_id ==
  899. dsp->features.pcm_id) {
  900. /* dsp must be on a slot */
  901. if (dsp->pcm_slot_tx >= 0 &&
  902. dsp->pcm_slot_tx <
  903. sizeof(freeslots))
  904. freeslots[dsp->pcm_slot_tx] = 0;
  905. if (dsp->pcm_slot_rx >= 0 &&
  906. dsp->pcm_slot_rx <
  907. sizeof(freeslots))
  908. freeslots[dsp->pcm_slot_rx] = 0;
  909. }
  910. }
  911. i = 0;
  912. ii = member->dsp->features.pcm_slots;
  913. while (i < ii) {
  914. if (freeslots[i])
  915. break;
  916. i++;
  917. }
  918. if (i == ii) {
  919. /* no more slots available */
  920. if (dsp_debug & DEBUG_DSP_CMX)
  921. printk(KERN_DEBUG
  922. "%s conference %d cannot be formed,"
  923. " because no slot free\n",
  924. __func__, conf->id);
  925. goto conf_software;
  926. }
  927. if (dsp_debug & DEBUG_DSP_CMX)
  928. printk(KERN_DEBUG
  929. "%s changing dsp %s to HW conference "
  930. "%d slot %d\n", __func__,
  931. member->dsp->name, current_conf, i);
  932. /* assign free slot & set PCM & join conf */
  933. member->dsp->pcm_slot_tx = i;
  934. member->dsp->pcm_slot_rx = i;
  935. member->dsp->pcm_bank_tx = 2; /* loop */
  936. member->dsp->pcm_bank_rx = 2;
  937. member->dsp->hfc_conf = current_conf;
  938. dsp_cmx_hw_message(member->dsp, MISDN_CTRL_HFC_PCM_CONN,
  939. i, 2, i, 2);
  940. dsp_cmx_hw_message(member->dsp,
  941. MISDN_CTRL_HFC_CONF_JOIN, current_conf, 0, 0, 0);
  942. }
  943. return;
  944. }
  945. /*
  946. * no member is in a conference yet, so we find a free one
  947. */
  948. memset(freeunits, 1, sizeof(freeunits));
  949. list_for_each_entry(dsp, &dsp_ilist, list) {
  950. /* dsp must be on the same chip */
  951. if (dsp->features.hfc_id == same_hfc &&
  952. /* dsp must have joined a HW conference */
  953. dsp->hfc_conf >= 0 &&
  954. /* slot must be within range */
  955. dsp->hfc_conf < 8)
  956. freeunits[dsp->hfc_conf] = 0;
  957. }
  958. i = 0;
  959. ii = 8;
  960. while (i < ii) {
  961. if (freeunits[i])
  962. break;
  963. i++;
  964. }
  965. if (i == ii) {
  966. /* no more conferences available */
  967. if (dsp_debug & DEBUG_DSP_CMX)
  968. printk(KERN_DEBUG
  969. "%s conference %d cannot be formed, because "
  970. "no conference number free\n",
  971. __func__, conf->id);
  972. goto conf_software;
  973. }
  974. /* join all members */
  975. current_conf = i;
  976. goto join_members;
  977. }
  978. /*
  979. * conf_id != 0: join or change conference
  980. * conf_id == 0: split from conference if not already
  981. */
  982. int
  983. dsp_cmx_conf(struct dsp *dsp, u32 conf_id)
  984. {
  985. int err;
  986. struct dsp_conf *conf;
  987. struct dsp_conf_member *member;
  988. /* if conference doesn't change */
  989. if (dsp->conf_id == conf_id)
  990. return 0;
  991. /* first remove us from current conf */
  992. if (dsp->conf_id) {
  993. if (dsp_debug & DEBUG_DSP_CMX)
  994. printk(KERN_DEBUG "removing us from conference %d\n",
  995. dsp->conf->id);
  996. /* remove us from conf */
  997. conf = dsp->conf;
  998. err = dsp_cmx_del_conf_member(dsp);
  999. if (err)
  1000. return err;
  1001. dsp->conf_id = 0;
  1002. /* update hardware */
  1003. dsp_cmx_hardware(NULL, dsp);
  1004. /* conf now empty? */
  1005. if (list_empty(&conf->mlist)) {
  1006. if (dsp_debug & DEBUG_DSP_CMX)
  1007. printk(KERN_DEBUG
  1008. "conference is empty, so we remove it.\n");
  1009. err = dsp_cmx_del_conf(conf);
  1010. if (err)
  1011. return err;
  1012. } else {
  1013. /* update members left on conf */
  1014. dsp_cmx_hardware(conf, NULL);
  1015. }
  1016. }
  1017. /* if split */
  1018. if (!conf_id)
  1019. return 0;
  1020. /* now add us to conf */
  1021. if (dsp_debug & DEBUG_DSP_CMX)
  1022. printk(KERN_DEBUG "searching conference %d\n",
  1023. conf_id);
  1024. conf = dsp_cmx_search_conf(conf_id);
  1025. if (!conf) {
  1026. if (dsp_debug & DEBUG_DSP_CMX)
  1027. printk(KERN_DEBUG
  1028. "conference doesn't exist yet, creating.\n");
  1029. /* the conference doesn't exist, so we create */
  1030. conf = dsp_cmx_new_conf(conf_id);
  1031. if (!conf)
  1032. return -EINVAL;
  1033. } else if (!list_empty(&conf->mlist)) {
  1034. member = list_entry(conf->mlist.next, struct dsp_conf_member,
  1035. list);
  1036. if (dsp->hdlc && !member->dsp->hdlc) {
  1037. if (dsp_debug & DEBUG_DSP_CMX)
  1038. printk(KERN_DEBUG
  1039. "cannot join transparent conference.\n");
  1040. return -EINVAL;
  1041. }
  1042. if (!dsp->hdlc && member->dsp->hdlc) {
  1043. if (dsp_debug & DEBUG_DSP_CMX)
  1044. printk(KERN_DEBUG
  1045. "cannot join hdlc conference.\n");
  1046. return -EINVAL;
  1047. }
  1048. }
  1049. /* add conference member */
  1050. err = dsp_cmx_add_conf_member(dsp, conf);
  1051. if (err)
  1052. return err;
  1053. dsp->conf_id = conf_id;
  1054. /* if we are alone, we do nothing! */
  1055. if (list_empty(&conf->mlist)) {
  1056. if (dsp_debug & DEBUG_DSP_CMX)
  1057. printk(KERN_DEBUG
  1058. "we are alone in this conference, so exit.\n");
  1059. /* update hardware */
  1060. dsp_cmx_hardware(NULL, dsp);
  1061. return 0;
  1062. }
  1063. /* update members on conf */
  1064. dsp_cmx_hardware(conf, NULL);
  1065. return 0;
  1066. }
  1067. /*
  1068. * audio data is received from card
  1069. */
  1070. void
  1071. dsp_cmx_receive(struct dsp *dsp, struct sk_buff *skb)
  1072. {
  1073. u8 *d, *p;
  1074. int len = skb->len;
  1075. struct mISDNhead *hh = mISDN_HEAD_P(skb);
  1076. int w, i, ii;
  1077. /* check if we have sompen */
  1078. if (len < 1)
  1079. return;
  1080. /* half of the buffer should be larger than maximum packet size */
  1081. if (len >= CMX_BUFF_HALF) {
  1082. printk(KERN_ERR
  1083. "%s line %d: packet from card is too large (%d bytes). "
  1084. "please make card send smaller packets OR increase "
  1085. "CMX_BUFF_SIZE\n", __FILE__, __LINE__, len);
  1086. return;
  1087. }
  1088. /*
  1089. * initialize pointers if not already -
  1090. * also add delay if requested by PH_SIGNAL
  1091. */
  1092. if (dsp->rx_init) {
  1093. dsp->rx_init = 0;
  1094. if (dsp->features.unordered) {
  1095. dsp->rx_R = (hh->id & CMX_BUFF_MASK);
  1096. if (dsp->cmx_delay)
  1097. dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
  1098. & CMX_BUFF_MASK;
  1099. else
  1100. dsp->rx_W = (dsp->rx_R + (dsp_poll >> 1))
  1101. & CMX_BUFF_MASK;
  1102. } else {
  1103. dsp->rx_R = 0;
  1104. if (dsp->cmx_delay)
  1105. dsp->rx_W = dsp->cmx_delay;
  1106. else
  1107. dsp->rx_W = dsp_poll >> 1;
  1108. }
  1109. }
  1110. /* if frame contains time code, write directly */
  1111. if (dsp->features.unordered) {
  1112. dsp->rx_W = (hh->id & CMX_BUFF_MASK);
  1113. /* printk(KERN_DEBUG "%s %08x\n", dsp->name, hh->id); */
  1114. }
  1115. /*
  1116. * if we underrun (or maybe overrun),
  1117. * we set our new read pointer, and write silence to buffer
  1118. */
  1119. if (((dsp->rx_W-dsp->rx_R) & CMX_BUFF_MASK) >= CMX_BUFF_HALF) {
  1120. if (dsp_debug & DEBUG_DSP_CLOCK)
  1121. printk(KERN_DEBUG
  1122. "cmx_receive(dsp=%lx): UNDERRUN (or overrun the "
  1123. "maximum delay), adjusting read pointer! "
  1124. "(inst %s)\n", (u_long)dsp, dsp->name);
  1125. /* flush rx buffer and set delay to dsp_poll / 2 */
  1126. if (dsp->features.unordered) {
  1127. dsp->rx_R = (hh->id & CMX_BUFF_MASK);
  1128. if (dsp->cmx_delay)
  1129. dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
  1130. & CMX_BUFF_MASK;
  1131. dsp->rx_W = (dsp->rx_R + (dsp_poll >> 1))
  1132. & CMX_BUFF_MASK;
  1133. } else {
  1134. dsp->rx_R = 0;
  1135. if (dsp->cmx_delay)
  1136. dsp->rx_W = dsp->cmx_delay;
  1137. else
  1138. dsp->rx_W = dsp_poll >> 1;
  1139. }
  1140. memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff));
  1141. }
  1142. /* if we have reached double delay, jump back to middle */
  1143. if (dsp->cmx_delay)
  1144. if (((dsp->rx_W - dsp->rx_R) & CMX_BUFF_MASK) >=
  1145. (dsp->cmx_delay << 1)) {
  1146. if (dsp_debug & DEBUG_DSP_CLOCK)
  1147. printk(KERN_DEBUG
  1148. "cmx_receive(dsp=%lx): OVERRUN (because "
  1149. "twice the delay is reached), adjusting "
  1150. "read pointer! (inst %s)\n",
  1151. (u_long)dsp, dsp->name);
  1152. /* flush buffer */
  1153. if (dsp->features.unordered) {
  1154. dsp->rx_R = (hh->id & CMX_BUFF_MASK);
  1155. dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
  1156. & CMX_BUFF_MASK;
  1157. } else {
  1158. dsp->rx_R = 0;
  1159. dsp->rx_W = dsp->cmx_delay;
  1160. }
  1161. memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff));
  1162. }
  1163. /* show where to write */
  1164. #ifdef CMX_DEBUG
  1165. printk(KERN_DEBUG
  1166. "cmx_receive(dsp=%lx): rx_R(dsp)=%05x rx_W(dsp)=%05x len=%d %s\n",
  1167. (u_long)dsp, dsp->rx_R, dsp->rx_W, len, dsp->name);
  1168. #endif
  1169. /* write data into rx_buffer */
  1170. p = skb->data;
  1171. d = dsp->rx_buff;
  1172. w = dsp->rx_W;
  1173. i = 0;
  1174. ii = len;
  1175. while (i < ii) {
  1176. d[w++ & CMX_BUFF_MASK] = *p++;
  1177. i++;
  1178. }
  1179. /* increase write-pointer */
  1180. dsp->rx_W = ((dsp->rx_W+len) & CMX_BUFF_MASK);
  1181. }
  1182. /*
  1183. * send (mixed) audio data to card and control jitter
  1184. */
  1185. static void
  1186. dsp_cmx_send_member(struct dsp *dsp, int len, s32 *c, int members)
  1187. {
  1188. struct dsp_conf *conf = dsp->conf;
  1189. struct dsp *member, *other;
  1190. register s32 sample;
  1191. u8 *d, *p, *q, *o_q;
  1192. struct sk_buff *nskb, *txskb;
  1193. int r, rr, t, tt, o_r, o_rr;
  1194. int preload = 0;
  1195. struct mISDNhead *hh, *thh;
  1196. /* don't process if: */
  1197. if (!dsp->b_active) { /* if not active */
  1198. dsp->last_tx = 0;
  1199. return;
  1200. }
  1201. if (dsp->pcm_slot_tx >= 0 && /* connected to pcm slot */
  1202. dsp->tx_R == dsp->tx_W && /* AND no tx-data */
  1203. !(dsp->tone.tone && dsp->tone.software)) { /* AND not soft tones */
  1204. dsp->last_tx = 0;
  1205. return;
  1206. }
  1207. #ifdef CMX_DEBUG
  1208. printk(KERN_DEBUG
  1209. "SEND members=%d dsp=%s, conf=%p, rx_R=%05x rx_W=%05x\n",
  1210. members, dsp->name, conf, dsp->rx_R, dsp->rx_W);
  1211. #endif
  1212. /* preload if we have delay set */
  1213. if (dsp->cmx_delay && !dsp->last_tx) {
  1214. preload = len;
  1215. if (preload < 128)
  1216. preload = 128;
  1217. }
  1218. /* PREPARE RESULT */
  1219. nskb = mI_alloc_skb(len + preload, GFP_ATOMIC);
  1220. if (!nskb) {
  1221. printk(KERN_ERR
  1222. "FATAL ERROR in mISDN_dsp.o: cannot alloc %d bytes\n",
  1223. len + preload);
  1224. return;
  1225. }
  1226. hh = mISDN_HEAD_P(nskb);
  1227. hh->prim = PH_DATA_REQ;
  1228. hh->id = 0;
  1229. dsp->last_tx = 1;
  1230. /* set pointers, indexes and stuff */
  1231. member = dsp;
  1232. p = dsp->tx_buff; /* transmit data */
  1233. q = dsp->rx_buff; /* received data */
  1234. d = skb_put(nskb, preload + len); /* result */
  1235. t = dsp->tx_R; /* tx-pointers */
  1236. tt = dsp->tx_W;
  1237. r = dsp->rx_R; /* rx-pointers */
  1238. rr = (r + len) & CMX_BUFF_MASK;
  1239. /* preload with silence, if required */
  1240. if (preload) {
  1241. memset(d, dsp_silence, preload);
  1242. d += preload;
  1243. }
  1244. /* PROCESS TONES/TX-DATA ONLY */
  1245. if (dsp->tone.tone && dsp->tone.software) {
  1246. /* -> copy tone */
  1247. dsp_tone_copy(dsp, d, len);
  1248. dsp->tx_R = 0; /* clear tx buffer */
  1249. dsp->tx_W = 0;
  1250. goto send_packet;
  1251. }
  1252. /* if we have tx-data but do not use mixing */
  1253. if (!dsp->tx_mix && t != tt) {
  1254. /* -> send tx-data and continue when not enough */
  1255. #ifdef CMX_TX_DEBUG
  1256. sprintf(debugbuf, "TX sending (%04x-%04x)%p: ", t, tt, p);
  1257. #endif
  1258. while (r != rr && t != tt) {
  1259. #ifdef CMX_TX_DEBUG
  1260. if (strlen(debugbuf) < 48)
  1261. sprintf(debugbuf+strlen(debugbuf), " %02x", p[t]);
  1262. #endif
  1263. *d++ = p[t]; /* write tx_buff */
  1264. t = (t+1) & CMX_BUFF_MASK;
  1265. r = (r+1) & CMX_BUFF_MASK;
  1266. }
  1267. if (r == rr) {
  1268. dsp->tx_R = t;
  1269. #ifdef CMX_TX_DEBUG
  1270. printk(KERN_DEBUG "%s\n", debugbuf);
  1271. #endif
  1272. goto send_packet;
  1273. }
  1274. }
  1275. #ifdef CMX_TX_DEBUG
  1276. printk(KERN_DEBUG "%s\n", debugbuf);
  1277. #endif
  1278. /* PROCESS DATA (one member / no conf) */
  1279. if (!conf || members <= 1) {
  1280. /* -> if echo is NOT enabled */
  1281. if (!dsp->echo) {
  1282. /* -> send tx-data if available or use 0-volume */
  1283. while (r != rr && t != tt) {
  1284. *d++ = p[t]; /* write tx_buff */
  1285. t = (t+1) & CMX_BUFF_MASK;
  1286. r = (r+1) & CMX_BUFF_MASK;
  1287. }
  1288. if (r != rr) {
  1289. if (dsp_debug & DEBUG_DSP_CLOCK)
  1290. printk(KERN_DEBUG "%s: RX empty\n",
  1291. __func__);
  1292. memset(d, dsp_silence, (rr-r)&CMX_BUFF_MASK);
  1293. }
  1294. /* -> if echo is enabled */
  1295. } else {
  1296. /*
  1297. * -> mix tx-data with echo if available,
  1298. * or use echo only
  1299. */
  1300. while (r != rr && t != tt) {
  1301. *d++ = dsp_audio_mix_law[(p[t]<<8)|q[r]];
  1302. t = (t+1) & CMX_BUFF_MASK;
  1303. r = (r+1) & CMX_BUFF_MASK;
  1304. }
  1305. while (r != rr) {
  1306. *d++ = q[r]; /* echo */
  1307. r = (r+1) & CMX_BUFF_MASK;
  1308. }
  1309. }
  1310. dsp->tx_R = t;
  1311. goto send_packet;
  1312. }
  1313. /* PROCESS DATA (two members) */
  1314. #ifdef CMX_CONF_DEBUG
  1315. if (0) {
  1316. #else
  1317. if (members == 2) {
  1318. #endif
  1319. /* "other" becomes other party */
  1320. other = (list_entry(conf->mlist.next,
  1321. struct dsp_conf_member, list))->dsp;
  1322. if (other == member)
  1323. other = (list_entry(conf->mlist.prev,
  1324. struct dsp_conf_member, list))->dsp;
  1325. o_q = other->rx_buff; /* received data */
  1326. o_rr = (other->rx_R + len) & CMX_BUFF_MASK;
  1327. /* end of rx-pointer */
  1328. o_r = (o_rr - rr + r) & CMX_BUFF_MASK;
  1329. /* start rx-pointer at current read position*/
  1330. /* -> if echo is NOT enabled */
  1331. if (!dsp->echo) {
  1332. /*
  1333. * -> copy other member's rx-data,
  1334. * if tx-data is available, mix
  1335. */
  1336. while (o_r != o_rr && t != tt) {
  1337. *d++ = dsp_audio_mix_law[(p[t]<<8)|o_q[o_r]];
  1338. t = (t+1) & CMX_BUFF_MASK;
  1339. o_r = (o_r+1) & CMX_BUFF_MASK;
  1340. }
  1341. while (o_r != o_rr) {
  1342. *d++ = o_q[o_r];
  1343. o_r = (o_r+1) & CMX_BUFF_MASK;
  1344. }
  1345. /* -> if echo is enabled */
  1346. } else {
  1347. /*
  1348. * -> mix other member's rx-data with echo,
  1349. * if tx-data is available, mix
  1350. */
  1351. while (r != rr && t != tt) {
  1352. sample = dsp_audio_law_to_s32[p[t]] +
  1353. dsp_audio_law_to_s32[q[r]] +
  1354. dsp_audio_law_to_s32[o_q[o_r]];
  1355. if (sample < -32768)
  1356. sample = -32768;
  1357. else if (sample > 32767)
  1358. sample = 32767;
  1359. *d++ = dsp_audio_s16_to_law[sample & 0xffff];
  1360. /* tx-data + rx_data + echo */
  1361. t = (t+1) & CMX_BUFF_MASK;
  1362. r = (r+1) & CMX_BUFF_MASK;
  1363. o_r = (o_r+1) & CMX_BUFF_MASK;
  1364. }
  1365. while (r != rr) {
  1366. *d++ = dsp_audio_mix_law[(q[r]<<8)|o_q[o_r]];
  1367. r = (r+1) & CMX_BUFF_MASK;
  1368. o_r = (o_r+1) & CMX_BUFF_MASK;
  1369. }
  1370. }
  1371. dsp->tx_R = t;
  1372. goto send_packet;
  1373. }
  1374. #ifdef DSP_NEVER_DEFINED
  1375. }
  1376. #endif
  1377. /* PROCESS DATA (three or more members) */
  1378. /* -> if echo is NOT enabled */
  1379. if (!dsp->echo) {
  1380. /*
  1381. * -> substract rx-data from conf-data,
  1382. * if tx-data is available, mix
  1383. */
  1384. while (r != rr && t != tt) {
  1385. sample = dsp_audio_law_to_s32[p[t]] + *c++ -
  1386. dsp_audio_law_to_s32[q[r]];
  1387. if (sample < -32768)
  1388. sample = -32768;
  1389. else if (sample > 32767)
  1390. sample = 32767;
  1391. *d++ = dsp_audio_s16_to_law[sample & 0xffff];
  1392. /* conf-rx+tx */
  1393. r = (r+1) & CMX_BUFF_MASK;
  1394. t = (t+1) & CMX_BUFF_MASK;
  1395. }
  1396. while (r != rr) {
  1397. sample = *c++ - dsp_audio_law_to_s32[q[r]];
  1398. if (sample < -32768)
  1399. sample = -32768;
  1400. else if (sample > 32767)
  1401. sample = 32767;
  1402. *d++ = dsp_audio_s16_to_law[sample & 0xffff];
  1403. /* conf-rx */
  1404. r = (r+1) & CMX_BUFF_MASK;
  1405. }
  1406. /* -> if echo is enabled */
  1407. } else {
  1408. /*
  1409. * -> encode conf-data, if tx-data
  1410. * is available, mix
  1411. */
  1412. while (r != rr && t != tt) {
  1413. sample = dsp_audio_law_to_s32[p[t]] + *c++;
  1414. if (sample < -32768)
  1415. sample = -32768;
  1416. else if (sample > 32767)
  1417. sample = 32767;
  1418. *d++ = dsp_audio_s16_to_law[sample & 0xffff];
  1419. /* conf(echo)+tx */
  1420. t = (t+1) & CMX_BUFF_MASK;
  1421. r = (r+1) & CMX_BUFF_MASK;
  1422. }
  1423. while (r != rr) {
  1424. sample = *c++;
  1425. if (sample < -32768)
  1426. sample = -32768;
  1427. else if (sample > 32767)
  1428. sample = 32767;
  1429. *d++ = dsp_audio_s16_to_law[sample & 0xffff];
  1430. /* conf(echo) */
  1431. r = (r+1) & CMX_BUFF_MASK;
  1432. }
  1433. }
  1434. dsp->tx_R = t;
  1435. goto send_packet;
  1436. send_packet:
  1437. /*
  1438. * send tx-data if enabled - don't filter,
  1439. * becuase we want what we send, not what we filtered
  1440. */
  1441. if (dsp->tx_data) {
  1442. /* PREPARE RESULT */
  1443. txskb = mI_alloc_skb(len, GFP_ATOMIC);
  1444. if (!txskb) {
  1445. printk(KERN_ERR
  1446. "FATAL ERROR in mISDN_dsp.o: "
  1447. "cannot alloc %d bytes\n", len);
  1448. } else {
  1449. thh = mISDN_HEAD_P(txskb);
  1450. thh->prim = DL_DATA_REQ;
  1451. thh->id = 0;
  1452. memcpy(skb_put(txskb, len), nskb->data+preload, len);
  1453. /* queue (trigger later) */
  1454. skb_queue_tail(&dsp->sendq, txskb);
  1455. }
  1456. }
  1457. /* adjust volume */
  1458. if (dsp->tx_volume)
  1459. dsp_change_volume(nskb, dsp->tx_volume);
  1460. /* pipeline */
  1461. if (dsp->pipeline.inuse)
  1462. dsp_pipeline_process_tx(&dsp->pipeline, nskb->data, nskb->len);
  1463. /* crypt */
  1464. if (dsp->bf_enable)
  1465. dsp_bf_encrypt(dsp, nskb->data, nskb->len);
  1466. /* queue and trigger */
  1467. skb_queue_tail(&dsp->sendq, nskb);
  1468. schedule_work(&dsp->workq);
  1469. }
  1470. static u32 jittercount; /* counter for jitter check */;
  1471. struct timer_list dsp_spl_tl;
  1472. u32 dsp_spl_jiffies; /* calculate the next time to fire */
  1473. static u16 dsp_count; /* last sample count */
  1474. static int dsp_count_valid ; /* if we have last sample count */
  1475. void
  1476. dsp_cmx_send(void *arg)
  1477. {
  1478. struct dsp_conf *conf;
  1479. struct dsp_conf_member *member;
  1480. struct dsp *dsp;
  1481. int mustmix, members;
  1482. s32 mixbuffer[MAX_POLL+100], *c;
  1483. u8 *p, *q;
  1484. int r, rr;
  1485. int jittercheck = 0, delay, i;
  1486. u_long flags;
  1487. u16 length, count;
  1488. /* lock */
  1489. spin_lock_irqsave(&dsp_lock, flags);
  1490. if (!dsp_count_valid) {
  1491. dsp_count = mISDN_clock_get();
  1492. length = dsp_poll;
  1493. dsp_count_valid = 1;
  1494. } else {
  1495. count = mISDN_clock_get();
  1496. length = count - dsp_count;
  1497. dsp_count = count;
  1498. }
  1499. if (length > MAX_POLL + 100)
  1500. length = MAX_POLL + 100;
  1501. /* printk(KERN_DEBUG "len=%d dsp_count=0x%x\n", length, dsp_count); */
  1502. /*
  1503. * check if jitter needs to be checked (this is every second)
  1504. */
  1505. jittercount += length;
  1506. if (jittercount >= 8000) {
  1507. jittercount -= 8000;
  1508. jittercheck = 1;
  1509. }
  1510. /* loop all members that do not require conference mixing */
  1511. list_for_each_entry(dsp, &dsp_ilist, list) {
  1512. if (dsp->hdlc)
  1513. continue;
  1514. conf = dsp->conf;
  1515. mustmix = 0;
  1516. members = 0;
  1517. if (conf) {
  1518. members = count_list_member(&conf->mlist);
  1519. #ifdef CMX_CONF_DEBUG
  1520. if (conf->software && members > 1)
  1521. #else
  1522. if (conf->software && members > 2)
  1523. #endif
  1524. mustmix = 1;
  1525. }
  1526. /* transmission required */
  1527. if (!mustmix) {
  1528. dsp_cmx_send_member(dsp, length, mixbuffer, members);
  1529. /*
  1530. * unused mixbuffer is given to prevent a
  1531. * potential null-pointer-bug
  1532. */
  1533. }
  1534. }
  1535. /* loop all members that require conference mixing */
  1536. list_for_each_entry(conf, &conf_ilist, list) {
  1537. /* count members and check hardware */
  1538. members = count_list_member(&conf->mlist);
  1539. #ifdef CMX_CONF_DEBUG
  1540. if (conf->software && members > 1) {
  1541. #else
  1542. if (conf->software && members > 2) {
  1543. #endif
  1544. /* check for hdlc conf */
  1545. member = list_entry(conf->mlist.next,
  1546. struct dsp_conf_member, list);
  1547. if (member->dsp->hdlc)
  1548. continue;
  1549. /* mix all data */
  1550. memset(mixbuffer, 0, length*sizeof(s32));
  1551. list_for_each_entry(member, &conf->mlist, list) {
  1552. dsp = member->dsp;
  1553. /* get range of data to mix */
  1554. c = mixbuffer;
  1555. q = dsp->rx_buff;
  1556. r = dsp->rx_R;
  1557. rr = (r + length) & CMX_BUFF_MASK;
  1558. /* add member's data */
  1559. while (r != rr) {
  1560. *c++ += dsp_audio_law_to_s32[q[r]];
  1561. r = (r+1) & CMX_BUFF_MASK;
  1562. }
  1563. }
  1564. /* process each member */
  1565. list_for_each_entry(member, &conf->mlist, list) {
  1566. /* transmission */
  1567. dsp_cmx_send_member(member->dsp, length,
  1568. mixbuffer, members);
  1569. }
  1570. }
  1571. }
  1572. /* delete rx-data, increment buffers, change pointers */
  1573. list_for_each_entry(dsp, &dsp_ilist, list) {
  1574. if (dsp->hdlc)
  1575. continue;
  1576. p = dsp->rx_buff;
  1577. q = dsp->tx_buff;
  1578. r = dsp->rx_R;
  1579. /* move receive pointer when receiving */
  1580. if (!dsp->rx_is_off) {
  1581. rr = (r + length) & CMX_BUFF_MASK;
  1582. /* delete rx-data */
  1583. while (r != rr) {
  1584. p[r] = dsp_silence;
  1585. r = (r+1) & CMX_BUFF_MASK;
  1586. }
  1587. /* increment rx-buffer pointer */
  1588. dsp->rx_R = r; /* write incremented read pointer */
  1589. }
  1590. /* check current rx_delay */
  1591. delay = (dsp->rx_W-dsp->rx_R) & CMX_BUFF_MASK;
  1592. if (delay >= CMX_BUFF_HALF)
  1593. delay = 0; /* will be the delay before next write */
  1594. /* check for lower delay */
  1595. if (delay < dsp->rx_delay[0])
  1596. dsp->rx_delay[0] = delay;
  1597. /* check current tx_delay */
  1598. delay = (dsp->tx_W-dsp->tx_R) & CMX_BUFF_MASK;
  1599. if (delay >= CMX_BUFF_HALF)
  1600. delay = 0; /* will be the delay before next write */
  1601. /* check for lower delay */
  1602. if (delay < dsp->tx_delay[0])
  1603. dsp->tx_delay[0] = delay;
  1604. if (jittercheck) {
  1605. /* find the lowest of all rx_delays */
  1606. delay = dsp->rx_delay[0];
  1607. i = 1;
  1608. while (i < MAX_SECONDS_JITTER_CHECK) {
  1609. if (delay > dsp->rx_delay[i])
  1610. delay = dsp->rx_delay[i];
  1611. i++;
  1612. }
  1613. /*
  1614. * remove rx_delay only if we have delay AND we
  1615. * have not preset cmx_delay AND
  1616. * the delay is greater dsp_poll
  1617. */
  1618. if (delay > dsp_poll && !dsp->cmx_delay) {
  1619. if (dsp_debug & DEBUG_DSP_CLOCK)
  1620. printk(KERN_DEBUG
  1621. "%s lowest rx_delay of %d bytes for"
  1622. " dsp %s are now removed.\n",
  1623. __func__, delay,
  1624. dsp->name);
  1625. r = dsp->rx_R;
  1626. rr = (r + delay - (dsp_poll >> 1))
  1627. & CMX_BUFF_MASK;
  1628. /* delete rx-data */
  1629. while (r != rr) {
  1630. p[r] = dsp_silence;
  1631. r = (r+1) & CMX_BUFF_MASK;
  1632. }
  1633. /* increment rx-buffer pointer */
  1634. dsp->rx_R = r;
  1635. /* write incremented read pointer */
  1636. }
  1637. /* find the lowest of all tx_delays */
  1638. delay = dsp->tx_delay[0];
  1639. i = 1;
  1640. while (i < MAX_SECONDS_JITTER_CHECK) {
  1641. if (delay > dsp->tx_delay[i])
  1642. delay = dsp->tx_delay[i];
  1643. i++;
  1644. }
  1645. /*
  1646. * remove delay only if we have delay AND we
  1647. * have enabled tx_dejitter
  1648. */
  1649. if (delay > dsp_poll && dsp->tx_dejitter) {
  1650. if (dsp_debug & DEBUG_DSP_CLOCK)
  1651. printk(KERN_DEBUG
  1652. "%s lowest tx_delay of %d bytes for"
  1653. " dsp %s are now removed.\n",
  1654. __func__, delay,
  1655. dsp->name);
  1656. r = dsp->tx_R;
  1657. rr = (r + delay - (dsp_poll >> 1))
  1658. & CMX_BUFF_MASK;
  1659. /* delete tx-data */
  1660. while (r != rr) {
  1661. q[r] = dsp_silence;
  1662. r = (r+1) & CMX_BUFF_MASK;
  1663. }
  1664. /* increment rx-buffer pointer */
  1665. dsp->tx_R = r;
  1666. /* write incremented read pointer */
  1667. }
  1668. /* scroll up delays */
  1669. i = MAX_SECONDS_JITTER_CHECK - 1;
  1670. while (i) {
  1671. dsp->rx_delay[i] = dsp->rx_delay[i-1];
  1672. dsp->tx_delay[i] = dsp->tx_delay[i-1];
  1673. i--;
  1674. }
  1675. dsp->tx_delay[0] = CMX_BUFF_HALF; /* (infinite) delay */
  1676. dsp->rx_delay[0] = CMX_BUFF_HALF; /* (infinite) delay */
  1677. }
  1678. }
  1679. /* if next event would be in the past ... */
  1680. if ((s32)(dsp_spl_jiffies+dsp_tics-jiffies) <= 0)
  1681. dsp_spl_jiffies = jiffies + 1;
  1682. else
  1683. dsp_spl_jiffies += dsp_tics;
  1684. dsp_spl_tl.expires = dsp_spl_jiffies;
  1685. add_timer(&dsp_spl_tl);
  1686. /* unlock */
  1687. spin_unlock_irqrestore(&dsp_lock, flags);
  1688. }
  1689. /*
  1690. * audio data is transmitted from upper layer to the dsp
  1691. */
  1692. void
  1693. dsp_cmx_transmit(struct dsp *dsp, struct sk_buff *skb)
  1694. {
  1695. u_int w, ww;
  1696. u8 *d, *p;
  1697. int space; /* todo: , l = skb->len; */
  1698. #ifdef CMX_TX_DEBUG
  1699. char debugbuf[256] = "";
  1700. #endif
  1701. /* check if there is enough space, and then copy */
  1702. w = dsp->tx_W;
  1703. ww = dsp->tx_R;
  1704. p = dsp->tx_buff;
  1705. d = skb->data;
  1706. space = (ww - w - 1) & CMX_BUFF_MASK;
  1707. /* write-pointer should not overrun nor reach read pointer */
  1708. if (space < skb->len) {
  1709. /* write to the space we have left */
  1710. ww = (ww - 1) & CMX_BUFF_MASK; /* end one byte prior tx_R */
  1711. if (dsp_debug & DEBUG_DSP_CLOCK)
  1712. printk(KERN_DEBUG "%s: TX overflow space=%d skb->len="
  1713. "%d, w=0x%04x, ww=0x%04x\n", __func__, space,
  1714. skb->len, w, ww);
  1715. } else
  1716. /* write until all byte are copied */
  1717. ww = (w + skb->len) & CMX_BUFF_MASK;
  1718. dsp->tx_W = ww;
  1719. /* show current buffer */
  1720. #ifdef CMX_DEBUG
  1721. printk(KERN_DEBUG
  1722. "cmx_transmit(dsp=%lx) %d bytes to 0x%x-0x%x. %s\n",
  1723. (u_long)dsp, (ww-w)&CMX_BUFF_MASK, w, ww, dsp->name);
  1724. #endif
  1725. /* copy transmit data to tx-buffer */
  1726. #ifdef CMX_TX_DEBUG
  1727. sprintf(debugbuf, "TX getting (%04x-%04x)%p: ", w, ww, p);
  1728. #endif
  1729. while (w != ww) {
  1730. #ifdef CMX_TX_DEBUG
  1731. if (strlen(debugbuf) < 48)
  1732. sprintf(debugbuf+strlen(debugbuf), " %02x", *d);
  1733. #endif
  1734. p[w] = *d++;
  1735. w = (w+1) & CMX_BUFF_MASK;
  1736. }
  1737. #ifdef CMX_TX_DEBUG
  1738. printk(KERN_DEBUG "%s\n", debugbuf);
  1739. #endif
  1740. }
  1741. /*
  1742. * hdlc data is received from card and sent to all members.
  1743. */
  1744. void
  1745. dsp_cmx_hdlc(struct dsp *dsp, struct sk_buff *skb)
  1746. {
  1747. struct sk_buff *nskb = NULL;
  1748. struct dsp_conf_member *member;
  1749. struct mISDNhead *hh;
  1750. /* not if not active */
  1751. if (!dsp->b_active)
  1752. return;
  1753. /* check if we have sompen */
  1754. if (skb->len < 1)
  1755. return;
  1756. /* no conf */
  1757. if (!dsp->conf) {
  1758. /* in case of hardware (echo) */
  1759. if (dsp->pcm_slot_tx >= 0)
  1760. return;
  1761. if (dsp->echo)
  1762. nskb = skb_clone(skb, GFP_ATOMIC);
  1763. if (nskb) {
  1764. hh = mISDN_HEAD_P(nskb);
  1765. hh->prim = PH_DATA_REQ;
  1766. hh->id = 0;
  1767. skb_queue_tail(&dsp->sendq, nskb);
  1768. schedule_work(&dsp->workq);
  1769. }
  1770. return;
  1771. }
  1772. /* in case of hardware conference */
  1773. if (dsp->conf->hardware)
  1774. return;
  1775. list_for_each_entry(member, &dsp->conf->mlist, list) {
  1776. if (dsp->echo || member->dsp != dsp) {
  1777. nskb = skb_clone(skb, GFP_ATOMIC);
  1778. if (nskb) {
  1779. hh = mISDN_HEAD_P(nskb);
  1780. hh->prim = PH_DATA_REQ;
  1781. hh->id = 0;
  1782. skb_queue_tail(&member->dsp->sendq, nskb);
  1783. schedule_work(&member->dsp->workq);
  1784. }
  1785. }
  1786. }
  1787. }