dsp_cmx.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886
  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_tx] = 0;
  411. if (finddsp->pcm_slot_tx >= 0 &&
  412. finddsp->pcm_slot_tx < sizeof(freeslots))
  413. freeslots[finddsp->pcm_slot_rx] = 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_tx] = 0;
  696. if (dsp->pcm_slot_tx >= 0 &&
  697. dsp->pcm_slot_tx <
  698. sizeof(freeslots))
  699. freeslots[dsp->pcm_slot_rx] = 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_tx] = 0;
  788. if (dsp->pcm_slot_tx >= 0 &&
  789. dsp->pcm_slot_tx <
  790. sizeof(freeslots))
  791. freeslots[dsp->pcm_slot_rx] = 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. dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
  1097. & CMX_BUFF_MASK;
  1098. } else {
  1099. dsp->rx_R = 0;
  1100. dsp->rx_W = dsp->cmx_delay;
  1101. }
  1102. }
  1103. /* if frame contains time code, write directly */
  1104. if (dsp->features.unordered) {
  1105. dsp->rx_W = (hh->id & CMX_BUFF_MASK);
  1106. /* printk(KERN_DEBUG "%s %08x\n", dsp->name, hh->id); */
  1107. }
  1108. /*
  1109. * if we underrun (or maybe overrun),
  1110. * we set our new read pointer, and write silence to buffer
  1111. */
  1112. if (((dsp->rx_W-dsp->rx_R) & CMX_BUFF_MASK) >= CMX_BUFF_HALF) {
  1113. if (dsp_debug & DEBUG_DSP_CMX)
  1114. printk(KERN_DEBUG
  1115. "cmx_receive(dsp=%lx): UNDERRUN (or overrun the "
  1116. "maximum delay), adjusting read pointer! "
  1117. "(inst %s)\n", (u_long)dsp, dsp->name);
  1118. /* flush buffer */
  1119. if (dsp->features.unordered) {
  1120. dsp->rx_R = (hh->id & CMX_BUFF_MASK);
  1121. dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
  1122. & CMX_BUFF_MASK;
  1123. } else {
  1124. dsp->rx_R = 0;
  1125. dsp->rx_W = dsp->cmx_delay;
  1126. }
  1127. memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff));
  1128. }
  1129. /* if we have reached double delay, jump back to middle */
  1130. if (dsp->cmx_delay)
  1131. if (((dsp->rx_W - dsp->rx_R) & CMX_BUFF_MASK) >=
  1132. (dsp->cmx_delay << 1)) {
  1133. if (dsp_debug & DEBUG_DSP_CMX)
  1134. printk(KERN_DEBUG
  1135. "cmx_receive(dsp=%lx): OVERRUN (because "
  1136. "twice the delay is reached), adjusting "
  1137. "read pointer! (inst %s)\n",
  1138. (u_long)dsp, dsp->name);
  1139. /* flush buffer */
  1140. if (dsp->features.unordered) {
  1141. dsp->rx_R = (hh->id & CMX_BUFF_MASK);
  1142. dsp->rx_W = (dsp->rx_R + dsp->cmx_delay)
  1143. & CMX_BUFF_MASK;
  1144. } else {
  1145. dsp->rx_R = 0;
  1146. dsp->rx_W = dsp->cmx_delay;
  1147. }
  1148. memset(dsp->rx_buff, dsp_silence, sizeof(dsp->rx_buff));
  1149. }
  1150. /* show where to write */
  1151. #ifdef CMX_DEBUG
  1152. printk(KERN_DEBUG
  1153. "cmx_receive(dsp=%lx): rx_R(dsp)=%05x rx_W(dsp)=%05x len=%d %s\n",
  1154. (u_long)dsp, dsp->rx_R, dsp->rx_W, len, dsp->name);
  1155. #endif
  1156. /* write data into rx_buffer */
  1157. p = skb->data;
  1158. d = dsp->rx_buff;
  1159. w = dsp->rx_W;
  1160. i = 0;
  1161. ii = len;
  1162. while (i < ii) {
  1163. d[w++ & CMX_BUFF_MASK] = *p++;
  1164. i++;
  1165. }
  1166. /* increase write-pointer */
  1167. dsp->rx_W = ((dsp->rx_W+len) & CMX_BUFF_MASK);
  1168. }
  1169. /*
  1170. * send (mixed) audio data to card and control jitter
  1171. */
  1172. static void
  1173. dsp_cmx_send_member(struct dsp *dsp, int len, s32 *c, int members)
  1174. {
  1175. struct dsp_conf *conf = dsp->conf;
  1176. struct dsp *member, *other;
  1177. register s32 sample;
  1178. u8 *d, *p, *q, *o_q;
  1179. struct sk_buff *nskb, *txskb;
  1180. int r, rr, t, tt, o_r, o_rr;
  1181. int preload = 0;
  1182. struct mISDNhead *hh, *thh;
  1183. /* don't process if: */
  1184. if (!dsp->b_active) { /* if not active */
  1185. dsp->last_tx = 0;
  1186. return;
  1187. }
  1188. if (dsp->pcm_slot_tx >= 0 && /* connected to pcm slot */
  1189. dsp->tx_R == dsp->tx_W && /* AND no tx-data */
  1190. !(dsp->tone.tone && dsp->tone.software)) { /* AND not soft tones */
  1191. dsp->last_tx = 0;
  1192. return;
  1193. }
  1194. #ifdef CMX_DEBUG
  1195. printk(KERN_DEBUG
  1196. "SEND members=%d dsp=%s, conf=%p, rx_R=%05x rx_W=%05x\n",
  1197. members, dsp->name, conf, dsp->rx_R, dsp->rx_W);
  1198. #endif
  1199. /* preload if we have delay set */
  1200. if (dsp->cmx_delay && !dsp->last_tx) {
  1201. preload = len;
  1202. if (preload < 128)
  1203. preload = 128;
  1204. }
  1205. /* PREPARE RESULT */
  1206. nskb = mI_alloc_skb(len + preload, GFP_ATOMIC);
  1207. if (!nskb) {
  1208. printk(KERN_ERR
  1209. "FATAL ERROR in mISDN_dsp.o: cannot alloc %d bytes\n",
  1210. len + preload);
  1211. return;
  1212. }
  1213. hh = mISDN_HEAD_P(nskb);
  1214. hh->prim = PH_DATA_REQ;
  1215. hh->id = 0;
  1216. dsp->last_tx = 1;
  1217. /* set pointers, indexes and stuff */
  1218. member = dsp;
  1219. p = dsp->tx_buff; /* transmit data */
  1220. q = dsp->rx_buff; /* received data */
  1221. d = skb_put(nskb, preload + len); /* result */
  1222. t = dsp->tx_R; /* tx-pointers */
  1223. tt = dsp->tx_W;
  1224. r = dsp->rx_R; /* rx-pointers */
  1225. rr = (r + len) & CMX_BUFF_MASK;
  1226. /* preload with silence, if required */
  1227. if (preload) {
  1228. memset(d, dsp_silence, preload);
  1229. d += preload;
  1230. }
  1231. /* PROCESS TONES/TX-DATA ONLY */
  1232. if (dsp->tone.tone && dsp->tone.software) {
  1233. /* -> copy tone */
  1234. dsp_tone_copy(dsp, d, len);
  1235. dsp->tx_R = 0; /* clear tx buffer */
  1236. dsp->tx_W = 0;
  1237. goto send_packet;
  1238. }
  1239. /* if we have tx-data but do not use mixing */
  1240. if (!dsp->tx_mix && t != tt) {
  1241. /* -> send tx-data and continue when not enough */
  1242. #ifdef CMX_TX_DEBUG
  1243. sprintf(debugbuf, "TX sending (%04x-%04x)%p: ", t, tt, p);
  1244. #endif
  1245. while (r != rr && t != tt) {
  1246. #ifdef CMX_TX_DEBUG
  1247. if (strlen(debugbuf) < 48)
  1248. sprintf(debugbuf+strlen(debugbuf), " %02x", p[t]);
  1249. #endif
  1250. *d++ = p[t]; /* write tx_buff */
  1251. t = (t+1) & CMX_BUFF_MASK;
  1252. r = (r+1) & CMX_BUFF_MASK;
  1253. }
  1254. if (r == rr) {
  1255. dsp->tx_R = t;
  1256. #ifdef CMX_TX_DEBUG
  1257. printk(KERN_DEBUG "%s\n", debugbuf);
  1258. #endif
  1259. goto send_packet;
  1260. }
  1261. }
  1262. #ifdef CMX_TX_DEBUG
  1263. printk(KERN_DEBUG "%s\n", debugbuf);
  1264. #endif
  1265. /* PROCESS DATA (one member / no conf) */
  1266. if (!conf || members <= 1) {
  1267. /* -> if echo is NOT enabled */
  1268. if (!dsp->echo) {
  1269. /* -> send tx-data if available or use 0-volume */
  1270. while (r != rr && t != tt) {
  1271. *d++ = p[t]; /* write tx_buff */
  1272. t = (t+1) & CMX_BUFF_MASK;
  1273. r = (r+1) & CMX_BUFF_MASK;
  1274. }
  1275. if (r != rr)
  1276. memset(d, dsp_silence, (rr-r)&CMX_BUFF_MASK);
  1277. /* -> if echo is enabled */
  1278. } else {
  1279. /*
  1280. * -> mix tx-data with echo if available,
  1281. * or use echo only
  1282. */
  1283. while (r != rr && t != tt) {
  1284. *d++ = dsp_audio_mix_law[(p[t]<<8)|q[r]];
  1285. t = (t+1) & CMX_BUFF_MASK;
  1286. r = (r+1) & CMX_BUFF_MASK;
  1287. }
  1288. while (r != rr) {
  1289. *d++ = q[r]; /* echo */
  1290. r = (r+1) & CMX_BUFF_MASK;
  1291. }
  1292. }
  1293. dsp->tx_R = t;
  1294. goto send_packet;
  1295. }
  1296. /* PROCESS DATA (two members) */
  1297. #ifdef CMX_CONF_DEBUG
  1298. if (0) {
  1299. #else
  1300. if (members == 2) {
  1301. #endif
  1302. /* "other" becomes other party */
  1303. other = (list_entry(conf->mlist.next,
  1304. struct dsp_conf_member, list))->dsp;
  1305. if (other == member)
  1306. other = (list_entry(conf->mlist.prev,
  1307. struct dsp_conf_member, list))->dsp;
  1308. o_q = other->rx_buff; /* received data */
  1309. o_rr = (other->rx_R + len) & CMX_BUFF_MASK;
  1310. /* end of rx-pointer */
  1311. o_r = (o_rr - rr + r) & CMX_BUFF_MASK;
  1312. /* start rx-pointer at current read position*/
  1313. /* -> if echo is NOT enabled */
  1314. if (!dsp->echo) {
  1315. /*
  1316. * -> copy other member's rx-data,
  1317. * if tx-data is available, mix
  1318. */
  1319. while (o_r != o_rr && t != tt) {
  1320. *d++ = dsp_audio_mix_law[(p[t]<<8)|o_q[o_r]];
  1321. t = (t+1) & CMX_BUFF_MASK;
  1322. o_r = (o_r+1) & CMX_BUFF_MASK;
  1323. }
  1324. while (o_r != o_rr) {
  1325. *d++ = o_q[o_r];
  1326. o_r = (o_r+1) & CMX_BUFF_MASK;
  1327. }
  1328. /* -> if echo is enabled */
  1329. } else {
  1330. /*
  1331. * -> mix other member's rx-data with echo,
  1332. * if tx-data is available, mix
  1333. */
  1334. while (r != rr && t != tt) {
  1335. sample = dsp_audio_law_to_s32[p[t]] +
  1336. dsp_audio_law_to_s32[q[r]] +
  1337. dsp_audio_law_to_s32[o_q[o_r]];
  1338. if (sample < -32768)
  1339. sample = -32768;
  1340. else if (sample > 32767)
  1341. sample = 32767;
  1342. *d++ = dsp_audio_s16_to_law[sample & 0xffff];
  1343. /* tx-data + rx_data + echo */
  1344. t = (t+1) & CMX_BUFF_MASK;
  1345. r = (r+1) & CMX_BUFF_MASK;
  1346. o_r = (o_r+1) & CMX_BUFF_MASK;
  1347. }
  1348. while (r != rr) {
  1349. *d++ = dsp_audio_mix_law[(q[r]<<8)|o_q[o_r]];
  1350. r = (r+1) & CMX_BUFF_MASK;
  1351. o_r = (o_r+1) & CMX_BUFF_MASK;
  1352. }
  1353. }
  1354. dsp->tx_R = t;
  1355. goto send_packet;
  1356. }
  1357. #ifdef DSP_NEVER_DEFINED
  1358. }
  1359. #endif
  1360. /* PROCESS DATA (three or more members) */
  1361. /* -> if echo is NOT enabled */
  1362. if (!dsp->echo) {
  1363. /*
  1364. * -> substract rx-data from conf-data,
  1365. * if tx-data is available, mix
  1366. */
  1367. while (r != rr && t != tt) {
  1368. sample = dsp_audio_law_to_s32[p[t]] + *c++ -
  1369. dsp_audio_law_to_s32[q[r]];
  1370. if (sample < -32768)
  1371. sample = -32768;
  1372. else if (sample > 32767)
  1373. sample = 32767;
  1374. *d++ = dsp_audio_s16_to_law[sample & 0xffff];
  1375. /* conf-rx+tx */
  1376. r = (r+1) & CMX_BUFF_MASK;
  1377. t = (t+1) & CMX_BUFF_MASK;
  1378. }
  1379. while (r != rr) {
  1380. sample = *c++ - dsp_audio_law_to_s32[q[r]];
  1381. if (sample < -32768)
  1382. sample = -32768;
  1383. else if (sample > 32767)
  1384. sample = 32767;
  1385. *d++ = dsp_audio_s16_to_law[sample & 0xffff];
  1386. /* conf-rx */
  1387. r = (r+1) & CMX_BUFF_MASK;
  1388. }
  1389. /* -> if echo is enabled */
  1390. } else {
  1391. /*
  1392. * -> encode conf-data, if tx-data
  1393. * is available, mix
  1394. */
  1395. while (r != rr && t != tt) {
  1396. sample = dsp_audio_law_to_s32[p[t]] + *c++;
  1397. if (sample < -32768)
  1398. sample = -32768;
  1399. else if (sample > 32767)
  1400. sample = 32767;
  1401. *d++ = dsp_audio_s16_to_law[sample & 0xffff];
  1402. /* conf(echo)+tx */
  1403. t = (t+1) & CMX_BUFF_MASK;
  1404. r = (r+1) & CMX_BUFF_MASK;
  1405. }
  1406. while (r != rr) {
  1407. sample = *c++;
  1408. if (sample < -32768)
  1409. sample = -32768;
  1410. else if (sample > 32767)
  1411. sample = 32767;
  1412. *d++ = dsp_audio_s16_to_law[sample & 0xffff];
  1413. /* conf(echo) */
  1414. r = (r+1) & CMX_BUFF_MASK;
  1415. }
  1416. }
  1417. dsp->tx_R = t;
  1418. goto send_packet;
  1419. send_packet:
  1420. /*
  1421. * send tx-data if enabled - don't filter,
  1422. * becuase we want what we send, not what we filtered
  1423. */
  1424. if (dsp->tx_data) {
  1425. /* PREPARE RESULT */
  1426. txskb = mI_alloc_skb(len, GFP_ATOMIC);
  1427. if (!txskb) {
  1428. printk(KERN_ERR
  1429. "FATAL ERROR in mISDN_dsp.o: "
  1430. "cannot alloc %d bytes\n", len);
  1431. } else {
  1432. thh = mISDN_HEAD_P(txskb);
  1433. thh->prim = DL_DATA_REQ;
  1434. thh->id = 0;
  1435. memcpy(skb_put(txskb, len), nskb->data+preload, len);
  1436. /* queue (trigger later) */
  1437. skb_queue_tail(&dsp->sendq, txskb);
  1438. }
  1439. }
  1440. /* adjust volume */
  1441. if (dsp->tx_volume)
  1442. dsp_change_volume(nskb, dsp->tx_volume);
  1443. /* pipeline */
  1444. if (dsp->pipeline.inuse)
  1445. dsp_pipeline_process_tx(&dsp->pipeline, nskb->data, nskb->len);
  1446. /* crypt */
  1447. if (dsp->bf_enable)
  1448. dsp_bf_encrypt(dsp, nskb->data, nskb->len);
  1449. /* queue and trigger */
  1450. skb_queue_tail(&dsp->sendq, nskb);
  1451. schedule_work(&dsp->workq);
  1452. }
  1453. u32 samplecount;
  1454. struct timer_list dsp_spl_tl;
  1455. u32 dsp_spl_jiffies; /* calculate the next time to fire */
  1456. u32 dsp_start_jiffies; /* jiffies at the time, the calculation begins */
  1457. struct timeval dsp_start_tv; /* time at start of calculation */
  1458. void
  1459. dsp_cmx_send(void *arg)
  1460. {
  1461. struct dsp_conf *conf;
  1462. struct dsp_conf_member *member;
  1463. struct dsp *dsp;
  1464. int mustmix, members;
  1465. s32 mixbuffer[MAX_POLL+100], *c;
  1466. u8 *p, *q;
  1467. int r, rr;
  1468. int jittercheck = 0, delay, i;
  1469. u_long flags;
  1470. struct timeval tv;
  1471. u32 elapsed;
  1472. s16 length;
  1473. /* lock */
  1474. spin_lock_irqsave(&dsp_lock, flags);
  1475. if (!dsp_start_tv.tv_sec) {
  1476. do_gettimeofday(&dsp_start_tv);
  1477. length = dsp_poll;
  1478. } else {
  1479. do_gettimeofday(&tv);
  1480. elapsed = ((tv.tv_sec - dsp_start_tv.tv_sec) * 8000)
  1481. + ((s32)(tv.tv_usec / 125) - (dsp_start_tv.tv_usec / 125));
  1482. dsp_start_tv.tv_sec = tv.tv_sec;
  1483. dsp_start_tv.tv_usec = tv.tv_usec;
  1484. length = elapsed;
  1485. }
  1486. if (length > MAX_POLL + 100)
  1487. length = MAX_POLL + 100;
  1488. /* printk(KERN_DEBUG "len=%d dsp_count=0x%x.%04x dsp_poll_diff=0x%x.%04x\n",
  1489. length, dsp_count >> 16, dsp_count & 0xffff, dsp_poll_diff >> 16,
  1490. dsp_poll_diff & 0xffff);
  1491. */
  1492. /*
  1493. * check if jitter needs to be checked
  1494. * (this is about every second = 8192 samples)
  1495. */
  1496. samplecount += length;
  1497. if ((samplecount & 8191) < length)
  1498. jittercheck = 1;
  1499. /* loop all members that do not require conference mixing */
  1500. list_for_each_entry(dsp, &dsp_ilist, list) {
  1501. if (dsp->hdlc)
  1502. continue;
  1503. conf = dsp->conf;
  1504. mustmix = 0;
  1505. members = 0;
  1506. if (conf) {
  1507. members = count_list_member(&conf->mlist);
  1508. #ifdef CMX_CONF_DEBUG
  1509. if (conf->software && members > 1)
  1510. #else
  1511. if (conf->software && members > 2)
  1512. #endif
  1513. mustmix = 1;
  1514. }
  1515. /* transmission required */
  1516. if (!mustmix) {
  1517. dsp_cmx_send_member(dsp, length, mixbuffer, members);
  1518. /*
  1519. * unused mixbuffer is given to prevent a
  1520. * potential null-pointer-bug
  1521. */
  1522. }
  1523. }
  1524. /* loop all members that require conference mixing */
  1525. list_for_each_entry(conf, &conf_ilist, list) {
  1526. /* count members and check hardware */
  1527. members = count_list_member(&conf->mlist);
  1528. #ifdef CMX_CONF_DEBUG
  1529. if (conf->software && members > 1) {
  1530. #else
  1531. if (conf->software && members > 2) {
  1532. #endif
  1533. /* check for hdlc conf */
  1534. member = list_entry(conf->mlist.next,
  1535. struct dsp_conf_member, list);
  1536. if (member->dsp->hdlc)
  1537. continue;
  1538. /* mix all data */
  1539. memset(mixbuffer, 0, length*sizeof(s32));
  1540. list_for_each_entry(member, &conf->mlist, list) {
  1541. dsp = member->dsp;
  1542. /* get range of data to mix */
  1543. c = mixbuffer;
  1544. q = dsp->rx_buff;
  1545. r = dsp->rx_R;
  1546. rr = (r + length) & CMX_BUFF_MASK;
  1547. /* add member's data */
  1548. while (r != rr) {
  1549. *c++ += dsp_audio_law_to_s32[q[r]];
  1550. r = (r+1) & CMX_BUFF_MASK;
  1551. }
  1552. }
  1553. /* process each member */
  1554. list_for_each_entry(member, &conf->mlist, list) {
  1555. /* transmission */
  1556. dsp_cmx_send_member(member->dsp, length,
  1557. mixbuffer, members);
  1558. }
  1559. }
  1560. }
  1561. /* delete rx-data, increment buffers, change pointers */
  1562. list_for_each_entry(dsp, &dsp_ilist, list) {
  1563. if (dsp->hdlc)
  1564. continue;
  1565. p = dsp->rx_buff;
  1566. q = dsp->tx_buff;
  1567. r = dsp->rx_R;
  1568. /* move receive pointer when receiving */
  1569. if (!dsp->rx_is_off) {
  1570. rr = (r + length) & CMX_BUFF_MASK;
  1571. /* delete rx-data */
  1572. while (r != rr) {
  1573. p[r] = dsp_silence;
  1574. r = (r+1) & CMX_BUFF_MASK;
  1575. }
  1576. /* increment rx-buffer pointer */
  1577. dsp->rx_R = r; /* write incremented read pointer */
  1578. }
  1579. /* check current rx_delay */
  1580. delay = (dsp->rx_W-dsp->rx_R) & CMX_BUFF_MASK;
  1581. if (delay >= CMX_BUFF_HALF)
  1582. delay = 0; /* will be the delay before next write */
  1583. /* check for lower delay */
  1584. if (delay < dsp->rx_delay[0])
  1585. dsp->rx_delay[0] = delay;
  1586. /* check current tx_delay */
  1587. delay = (dsp->tx_W-dsp->tx_R) & CMX_BUFF_MASK;
  1588. if (delay >= CMX_BUFF_HALF)
  1589. delay = 0; /* will be the delay before next write */
  1590. /* check for lower delay */
  1591. if (delay < dsp->tx_delay[0])
  1592. dsp->tx_delay[0] = delay;
  1593. if (jittercheck) {
  1594. /* find the lowest of all rx_delays */
  1595. delay = dsp->rx_delay[0];
  1596. i = 1;
  1597. while (i < MAX_SECONDS_JITTER_CHECK) {
  1598. if (delay > dsp->rx_delay[i])
  1599. delay = dsp->rx_delay[i];
  1600. i++;
  1601. }
  1602. /*
  1603. * remove rx_delay only if we have delay AND we
  1604. * have not preset cmx_delay
  1605. */
  1606. if (delay && !dsp->cmx_delay) {
  1607. if (dsp_debug & DEBUG_DSP_CMX)
  1608. printk(KERN_DEBUG
  1609. "%s lowest rx_delay of %d bytes for"
  1610. " dsp %s are now removed.\n",
  1611. __func__, delay,
  1612. dsp->name);
  1613. r = dsp->rx_R;
  1614. rr = (r + delay) & CMX_BUFF_MASK;
  1615. /* delete rx-data */
  1616. while (r != rr) {
  1617. p[r] = dsp_silence;
  1618. r = (r+1) & CMX_BUFF_MASK;
  1619. }
  1620. /* increment rx-buffer pointer */
  1621. dsp->rx_R = r;
  1622. /* write incremented read pointer */
  1623. }
  1624. /* find the lowest of all tx_delays */
  1625. delay = dsp->tx_delay[0];
  1626. i = 1;
  1627. while (i < MAX_SECONDS_JITTER_CHECK) {
  1628. if (delay > dsp->tx_delay[i])
  1629. delay = dsp->tx_delay[i];
  1630. i++;
  1631. }
  1632. /*
  1633. * remove delay only if we have delay AND we
  1634. * have enabled tx_dejitter
  1635. */
  1636. if (delay && dsp->tx_dejitter) {
  1637. if (dsp_debug & DEBUG_DSP_CMX)
  1638. printk(KERN_DEBUG
  1639. "%s lowest tx_delay of %d bytes for"
  1640. " dsp %s are now removed.\n",
  1641. __func__, delay,
  1642. dsp->name);
  1643. r = dsp->tx_R;
  1644. rr = (r + delay) & CMX_BUFF_MASK;
  1645. /* delete tx-data */
  1646. while (r != rr) {
  1647. q[r] = dsp_silence;
  1648. r = (r+1) & CMX_BUFF_MASK;
  1649. }
  1650. /* increment rx-buffer pointer */
  1651. dsp->tx_R = r;
  1652. /* write incremented read pointer */
  1653. }
  1654. /* scroll up delays */
  1655. i = MAX_SECONDS_JITTER_CHECK - 1;
  1656. while (i) {
  1657. dsp->rx_delay[i] = dsp->rx_delay[i-1];
  1658. dsp->tx_delay[i] = dsp->tx_delay[i-1];
  1659. i--;
  1660. }
  1661. dsp->tx_delay[0] = CMX_BUFF_HALF; /* (infinite) delay */
  1662. dsp->rx_delay[0] = CMX_BUFF_HALF; /* (infinite) delay */
  1663. }
  1664. }
  1665. /* if next event would be in the past ... */
  1666. if ((s32)(dsp_spl_jiffies+dsp_tics-jiffies) <= 0)
  1667. dsp_spl_jiffies = jiffies + 1;
  1668. else
  1669. dsp_spl_jiffies += dsp_tics;
  1670. dsp_spl_tl.expires = dsp_spl_jiffies;
  1671. add_timer(&dsp_spl_tl);
  1672. /* unlock */
  1673. spin_unlock_irqrestore(&dsp_lock, flags);
  1674. }
  1675. /*
  1676. * audio data is transmitted from upper layer to the dsp
  1677. */
  1678. void
  1679. dsp_cmx_transmit(struct dsp *dsp, struct sk_buff *skb)
  1680. {
  1681. u_int w, ww;
  1682. u8 *d, *p;
  1683. int space; /* todo: , l = skb->len; */
  1684. #ifdef CMX_TX_DEBUG
  1685. char debugbuf[256] = "";
  1686. #endif
  1687. /* check if there is enough space, and then copy */
  1688. w = dsp->tx_W;
  1689. ww = dsp->tx_R;
  1690. p = dsp->tx_buff;
  1691. d = skb->data;
  1692. space = ww-w;
  1693. if (space <= 0)
  1694. space += CMX_BUFF_SIZE;
  1695. /* write-pointer should not overrun nor reach read pointer */
  1696. if (space-1 < skb->len)
  1697. /* write to the space we have left */
  1698. ww = (ww - 1) & CMX_BUFF_MASK;
  1699. else
  1700. /* write until all byte are copied */
  1701. ww = (w + skb->len) & CMX_BUFF_MASK;
  1702. dsp->tx_W = ww;
  1703. /* show current buffer */
  1704. #ifdef CMX_DEBUG
  1705. printk(KERN_DEBUG
  1706. "cmx_transmit(dsp=%lx) %d bytes to 0x%x-0x%x. %s\n",
  1707. (u_long)dsp, (ww-w)&CMX_BUFF_MASK, w, ww, dsp->name);
  1708. #endif
  1709. /* copy transmit data to tx-buffer */
  1710. #ifdef CMX_TX_DEBUG
  1711. sprintf(debugbuf, "TX getting (%04x-%04x)%p: ", w, ww, p);
  1712. #endif
  1713. while (w != ww) {
  1714. #ifdef CMX_TX_DEBUG
  1715. if (strlen(debugbuf) < 48)
  1716. sprintf(debugbuf+strlen(debugbuf), " %02x", *d);
  1717. #endif
  1718. p[w] = *d++;
  1719. w = (w+1) & CMX_BUFF_MASK;
  1720. }
  1721. #ifdef CMX_TX_DEBUG
  1722. printk(KERN_DEBUG "%s\n", debugbuf);
  1723. #endif
  1724. }
  1725. /*
  1726. * hdlc data is received from card and sent to all members.
  1727. */
  1728. void
  1729. dsp_cmx_hdlc(struct dsp *dsp, struct sk_buff *skb)
  1730. {
  1731. struct sk_buff *nskb = NULL;
  1732. struct dsp_conf_member *member;
  1733. struct mISDNhead *hh;
  1734. /* not if not active */
  1735. if (!dsp->b_active)
  1736. return;
  1737. /* check if we have sompen */
  1738. if (skb->len < 1)
  1739. return;
  1740. /* no conf */
  1741. if (!dsp->conf) {
  1742. /* in case of hardware (echo) */
  1743. if (dsp->pcm_slot_tx >= 0)
  1744. return;
  1745. if (dsp->echo)
  1746. nskb = skb_clone(skb, GFP_ATOMIC);
  1747. if (nskb) {
  1748. hh = mISDN_HEAD_P(nskb);
  1749. hh->prim = PH_DATA_REQ;
  1750. hh->id = 0;
  1751. skb_queue_tail(&dsp->sendq, nskb);
  1752. schedule_work(&dsp->workq);
  1753. }
  1754. return;
  1755. }
  1756. /* in case of hardware conference */
  1757. if (dsp->conf->hardware)
  1758. return;
  1759. list_for_each_entry(member, &dsp->conf->mlist, list) {
  1760. if (dsp->echo || member->dsp != dsp) {
  1761. nskb = skb_clone(skb, GFP_ATOMIC);
  1762. if (nskb) {
  1763. hh = mISDN_HEAD_P(nskb);
  1764. hh->prim = PH_DATA_REQ;
  1765. hh->id = 0;
  1766. skb_queue_tail(&member->dsp->sendq, nskb);
  1767. schedule_work(&member->dsp->workq);
  1768. }
  1769. }
  1770. }
  1771. }