dsp_core.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228
  1. /*
  2. * Author Andreas Eversberg (jolly@eversberg.eu)
  3. * Based on source code structure by
  4. * Karsten Keil (keil@isdn4linux.de)
  5. *
  6. * This file is (c) under GNU PUBLIC LICENSE
  7. * For changes and modifications please read
  8. * ../../../Documentation/isdn/mISDN.cert
  9. *
  10. * Thanks to Karsten Keil (great drivers)
  11. * Cologne Chip (great chips)
  12. *
  13. * This module does:
  14. * Real-time tone generation
  15. * DTMF detection
  16. * Real-time cross-connection and conferrence
  17. * Compensate jitter due to system load and hardware fault.
  18. * All features are done in kernel space and will be realized
  19. * using hardware, if available and supported by chip set.
  20. * Blowfish encryption/decryption
  21. */
  22. /* STRUCTURE:
  23. *
  24. * The dsp module provides layer 2 for b-channels (64kbit). It provides
  25. * transparent audio forwarding with special digital signal processing:
  26. *
  27. * - (1) generation of tones
  28. * - (2) detection of dtmf tones
  29. * - (3) crossconnecting and conferences (clocking)
  30. * - (4) echo generation for delay test
  31. * - (5) volume control
  32. * - (6) disable receive data
  33. * - (7) pipeline
  34. * - (8) encryption/decryption
  35. *
  36. * Look:
  37. * TX RX
  38. * ------upper layer------
  39. * | ^
  40. * | |(6)
  41. * v |
  42. * +-----+-------------+-----+
  43. * |(3)(4) |
  44. * | CMX |
  45. * | |
  46. * | +-------------+
  47. * | | ^
  48. * | | |
  49. * |+---------+| +----+----+
  50. * ||(1) || |(2) |
  51. * || || | |
  52. * || Tones || | DTMF |
  53. * || || | |
  54. * || || | |
  55. * |+----+----+| +----+----+
  56. * +-----+-----+ ^
  57. * | |
  58. * v |
  59. * +----+----+ +----+----+
  60. * |(5) | |(5) |
  61. * | | | |
  62. * |TX Volume| |RX Volume|
  63. * | | | |
  64. * | | | |
  65. * +----+----+ +----+----+
  66. * | ^
  67. * | |
  68. * v |
  69. * +----+-------------+----+
  70. * |(7) |
  71. * | |
  72. * | Pipeline Processing |
  73. * | |
  74. * | |
  75. * +----+-------------+----+
  76. * | ^
  77. * | |
  78. * v |
  79. * +----+----+ +----+----+
  80. * |(8) | |(8) |
  81. * | | | |
  82. * | Encrypt | | Decrypt |
  83. * | | | |
  84. * | | | |
  85. * +----+----+ +----+----+
  86. * | ^
  87. * | |
  88. * v |
  89. * ------card layer------
  90. * TX RX
  91. *
  92. * Above you can see the logical data flow. If software is used to do the
  93. * process, it is actually the real data flow. If hardware is used, data
  94. * may not flow, but hardware commands to the card, to provide the data flow
  95. * as shown.
  96. *
  97. * NOTE: The channel must be activated in order to make dsp work, even if
  98. * no data flow to the upper layer is intended. Activation can be done
  99. * after and before controlling the setting using PH_CONTROL requests.
  100. *
  101. * DTMF: Will be detected by hardware if possible. It is done before CMX
  102. * processing.
  103. *
  104. * Tones: Will be generated via software if endless looped audio fifos are
  105. * not supported by hardware. Tones will override all data from CMX.
  106. * It is not required to join a conference to use tones at any time.
  107. *
  108. * CMX: Is transparent when not used. When it is used, it will do
  109. * crossconnections and conferences via software if not possible through
  110. * hardware. If hardware capability is available, hardware is used.
  111. *
  112. * Echo: Is generated by CMX and is used to check performane of hard and
  113. * software CMX.
  114. *
  115. * The CMX has special functions for conferences with one, two and more
  116. * members. It will allow different types of data flow. Receive and transmit
  117. * data to/form upper layer may be swithed on/off individually without loosing
  118. * features of CMX, Tones and DTMF.
  119. *
  120. * Echo Cancellation: Sometimes we like to cancel echo from the interface.
  121. * Note that a VoIP call may not have echo caused by the IP phone. The echo
  122. * is generated by the telephone line connected to it. Because the delay
  123. * is high, it becomes an echo. RESULT: Echo Cachelation is required if
  124. * both echo AND delay is applied to an interface.
  125. * Remember that software CMX always generates a more or less delay.
  126. *
  127. * If all used features can be realized in hardware, and if transmit and/or
  128. * receive data ist disabled, the card may not send/receive any data at all.
  129. * Not receiving is usefull if only announcements are played. Not sending is
  130. * usefull if an answering machine records audio. Not sending and receiving is
  131. * usefull during most states of the call. If supported by hardware, tones
  132. * will be played without cpu load. Small PBXs and NT-Mode applications will
  133. * not need expensive hardware when processing calls.
  134. *
  135. *
  136. * LOCKING:
  137. *
  138. * When data is received from upper or lower layer (card), the complete dsp
  139. * module is locked by a global lock. This lock MUST lock irq, because it
  140. * must lock timer events by DSP poll timer.
  141. * When data is ready to be transmitted down, the data is queued and sent
  142. * outside lock and timer event.
  143. * PH_CONTROL must not change any settings, join or split conference members
  144. * during process of data.
  145. *
  146. * HDLC:
  147. *
  148. * It works quite the same as transparent, except that HDLC data is forwarded
  149. * to all other conference members if no hardware bridging is possible.
  150. * Send data will be writte to sendq. Sendq will be sent if confirm is received.
  151. * Conference cannot join, if one member is not hdlc.
  152. *
  153. */
  154. #include <linux/delay.h>
  155. #include <linux/mISDNif.h>
  156. #include <linux/mISDNdsp.h>
  157. #include <linux/module.h>
  158. #include <linux/vmalloc.h>
  159. #include "core.h"
  160. #include "dsp.h"
  161. static const char *mISDN_dsp_revision = "2.0";
  162. static int debug;
  163. static int options;
  164. static int poll;
  165. static int dtmfthreshold = 100;
  166. MODULE_AUTHOR("Andreas Eversberg");
  167. module_param(debug, uint, S_IRUGO | S_IWUSR);
  168. module_param(options, uint, S_IRUGO | S_IWUSR);
  169. module_param(poll, uint, S_IRUGO | S_IWUSR);
  170. module_param(dtmfthreshold, uint, S_IRUGO | S_IWUSR);
  171. MODULE_LICENSE("GPL");
  172. /*int spinnest = 0;*/
  173. spinlock_t dsp_lock; /* global dsp lock */
  174. struct list_head dsp_ilist;
  175. struct list_head conf_ilist;
  176. int dsp_debug;
  177. int dsp_options;
  178. int dsp_poll, dsp_tics;
  179. /* check if rx may be turned off or must be turned on */
  180. static void
  181. dsp_rx_off_member(struct dsp *dsp)
  182. {
  183. struct mISDN_ctrl_req cq;
  184. int rx_off = 1;
  185. memset(&cq, 0, sizeof(cq));
  186. if (!dsp->features_rx_off)
  187. return;
  188. /* not disabled */
  189. if (!dsp->rx_disabled)
  190. rx_off = 0;
  191. /* software dtmf */
  192. else if (dsp->dtmf.software)
  193. rx_off = 0;
  194. /* echo in software */
  195. else if (dsp->echo && dsp->pcm_slot_tx < 0)
  196. rx_off = 0;
  197. /* bridge in software */
  198. else if (dsp->conf) {
  199. if (dsp->conf->software)
  200. rx_off = 0;
  201. }
  202. if (rx_off == dsp->rx_is_off)
  203. return;
  204. if (!dsp->ch.peer) {
  205. if (dsp_debug & DEBUG_DSP_CORE)
  206. printk(KERN_DEBUG "%s: no peer, no rx_off\n",
  207. __func__);
  208. return;
  209. }
  210. cq.op = MISDN_CTRL_RX_OFF;
  211. cq.p1 = rx_off;
  212. if (dsp->ch.peer->ctrl(dsp->ch.peer, CONTROL_CHANNEL, &cq)) {
  213. printk(KERN_DEBUG "%s: 2nd CONTROL_CHANNEL failed\n",
  214. __func__);
  215. return;
  216. }
  217. dsp->rx_is_off = rx_off;
  218. if (dsp_debug & DEBUG_DSP_CORE)
  219. printk(KERN_DEBUG "%s: %s set rx_off = %d\n",
  220. __func__, dsp->name, rx_off);
  221. }
  222. static void
  223. dsp_rx_off(struct dsp *dsp)
  224. {
  225. struct dsp_conf_member *member;
  226. if (dsp_options & DSP_OPT_NOHARDWARE)
  227. return;
  228. /* no conf */
  229. if (!dsp->conf) {
  230. dsp_rx_off_member(dsp);
  231. return;
  232. }
  233. /* check all members in conf */
  234. list_for_each_entry(member, &dsp->conf->mlist, list) {
  235. dsp_rx_off_member(member->dsp);
  236. }
  237. }
  238. /* enable "fill empty" feature */
  239. static void
  240. dsp_fill_empty(struct dsp *dsp)
  241. {
  242. struct mISDN_ctrl_req cq;
  243. memset(&cq, 0, sizeof(cq));
  244. if (!dsp->ch.peer) {
  245. if (dsp_debug & DEBUG_DSP_CORE)
  246. printk(KERN_DEBUG "%s: no peer, no fill_empty\n",
  247. __func__);
  248. return;
  249. }
  250. cq.op = MISDN_CTRL_FILL_EMPTY;
  251. cq.p1 = 1;
  252. if (dsp->ch.peer->ctrl(dsp->ch.peer, CONTROL_CHANNEL, &cq)) {
  253. printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n",
  254. __func__);
  255. return;
  256. }
  257. if (dsp_debug & DEBUG_DSP_CORE)
  258. printk(KERN_DEBUG "%s: %s set fill_empty = 1\n",
  259. __func__, dsp->name);
  260. }
  261. static int
  262. dsp_control_req(struct dsp *dsp, struct mISDNhead *hh, struct sk_buff *skb)
  263. {
  264. struct sk_buff *nskb;
  265. int ret = 0;
  266. int cont;
  267. u8 *data;
  268. int len;
  269. if (skb->len < sizeof(int))
  270. printk(KERN_ERR "%s: PH_CONTROL message too short\n", __func__);
  271. cont = *((int *)skb->data);
  272. len = skb->len - sizeof(int);
  273. data = skb->data + sizeof(int);
  274. switch (cont) {
  275. case DTMF_TONE_START: /* turn on DTMF */
  276. if (dsp->hdlc) {
  277. ret = -EINVAL;
  278. break;
  279. }
  280. if (dsp_debug & DEBUG_DSP_CORE)
  281. printk(KERN_DEBUG "%s: start dtmf\n", __func__);
  282. if (len == sizeof(int)) {
  283. if (dsp_debug & DEBUG_DSP_CORE)
  284. printk(KERN_NOTICE "changing DTMF Threshold "
  285. "to %d\n", *((int *)data));
  286. dsp->dtmf.treshold = (*(int *)data) * 10000;
  287. }
  288. /* init goertzel */
  289. dsp_dtmf_goertzel_init(dsp);
  290. /* check dtmf hardware */
  291. dsp_dtmf_hardware(dsp);
  292. break;
  293. case DTMF_TONE_STOP: /* turn off DTMF */
  294. if (dsp_debug & DEBUG_DSP_CORE)
  295. printk(KERN_DEBUG "%s: stop dtmf\n", __func__);
  296. dsp->dtmf.hardware = 0;
  297. dsp->dtmf.software = 0;
  298. break;
  299. case DSP_CONF_JOIN: /* join / update conference */
  300. if (len < sizeof(int)) {
  301. ret = -EINVAL;
  302. break;
  303. }
  304. if (*((u32 *)data) == 0)
  305. goto conf_split;
  306. if (dsp_debug & DEBUG_DSP_CORE)
  307. printk(KERN_DEBUG "%s: join conference %d\n",
  308. __func__, *((u32 *)data));
  309. ret = dsp_cmx_conf(dsp, *((u32 *)data));
  310. /* dsp_cmx_hardware will also be called here */
  311. dsp_rx_off(dsp);
  312. if (dsp_debug & DEBUG_DSP_CMX)
  313. dsp_cmx_debug(dsp);
  314. break;
  315. case DSP_CONF_SPLIT: /* remove from conference */
  316. conf_split:
  317. if (dsp_debug & DEBUG_DSP_CORE)
  318. printk(KERN_DEBUG "%s: release conference\n", __func__);
  319. ret = dsp_cmx_conf(dsp, 0);
  320. /* dsp_cmx_hardware will also be called here */
  321. if (dsp_debug & DEBUG_DSP_CMX)
  322. dsp_cmx_debug(dsp);
  323. dsp_rx_off(dsp);
  324. break;
  325. case DSP_TONE_PATT_ON: /* play tone */
  326. if (dsp->hdlc) {
  327. ret = -EINVAL;
  328. break;
  329. }
  330. if (len < sizeof(int)) {
  331. ret = -EINVAL;
  332. break;
  333. }
  334. if (dsp_debug & DEBUG_DSP_CORE)
  335. printk(KERN_DEBUG "%s: turn tone 0x%x on\n",
  336. __func__, *((int *)skb->data));
  337. ret = dsp_tone(dsp, *((int *)data));
  338. if (!ret) {
  339. dsp_cmx_hardware(dsp->conf, dsp);
  340. dsp_rx_off(dsp);
  341. }
  342. if (!dsp->tone.tone)
  343. goto tone_off;
  344. break;
  345. case DSP_TONE_PATT_OFF: /* stop tone */
  346. if (dsp->hdlc) {
  347. ret = -EINVAL;
  348. break;
  349. }
  350. if (dsp_debug & DEBUG_DSP_CORE)
  351. printk(KERN_DEBUG "%s: turn tone off\n", __func__);
  352. dsp_tone(dsp, 0);
  353. dsp_cmx_hardware(dsp->conf, dsp);
  354. dsp_rx_off(dsp);
  355. /* reset tx buffers (user space data) */
  356. tone_off:
  357. dsp->rx_W = 0;
  358. dsp->rx_R = 0;
  359. break;
  360. case DSP_VOL_CHANGE_TX: /* change volume */
  361. if (dsp->hdlc) {
  362. ret = -EINVAL;
  363. break;
  364. }
  365. if (len < sizeof(int)) {
  366. ret = -EINVAL;
  367. break;
  368. }
  369. dsp->tx_volume = *((int *)data);
  370. if (dsp_debug & DEBUG_DSP_CORE)
  371. printk(KERN_DEBUG "%s: change tx vol to %d\n",
  372. __func__, dsp->tx_volume);
  373. dsp_cmx_hardware(dsp->conf, dsp);
  374. dsp_dtmf_hardware(dsp);
  375. dsp_rx_off(dsp);
  376. break;
  377. case DSP_VOL_CHANGE_RX: /* change volume */
  378. if (dsp->hdlc) {
  379. ret = -EINVAL;
  380. break;
  381. }
  382. if (len < sizeof(int)) {
  383. ret = -EINVAL;
  384. break;
  385. }
  386. dsp->rx_volume = *((int *)data);
  387. if (dsp_debug & DEBUG_DSP_CORE)
  388. printk(KERN_DEBUG "%s: change rx vol to %d\n",
  389. __func__, dsp->tx_volume);
  390. dsp_cmx_hardware(dsp->conf, dsp);
  391. dsp_dtmf_hardware(dsp);
  392. dsp_rx_off(dsp);
  393. break;
  394. case DSP_ECHO_ON: /* enable echo */
  395. dsp->echo = 1; /* soft echo */
  396. if (dsp_debug & DEBUG_DSP_CORE)
  397. printk(KERN_DEBUG "%s: enable cmx-echo\n", __func__);
  398. dsp_cmx_hardware(dsp->conf, dsp);
  399. dsp_rx_off(dsp);
  400. if (dsp_debug & DEBUG_DSP_CMX)
  401. dsp_cmx_debug(dsp);
  402. break;
  403. case DSP_ECHO_OFF: /* disable echo */
  404. dsp->echo = 0;
  405. if (dsp_debug & DEBUG_DSP_CORE)
  406. printk(KERN_DEBUG "%s: disable cmx-echo\n", __func__);
  407. dsp_cmx_hardware(dsp->conf, dsp);
  408. dsp_rx_off(dsp);
  409. if (dsp_debug & DEBUG_DSP_CMX)
  410. dsp_cmx_debug(dsp);
  411. break;
  412. case DSP_RECEIVE_ON: /* enable receive to user space */
  413. if (dsp_debug & DEBUG_DSP_CORE)
  414. printk(KERN_DEBUG "%s: enable receive to user "
  415. "space\n", __func__);
  416. dsp->rx_disabled = 0;
  417. dsp_rx_off(dsp);
  418. break;
  419. case DSP_RECEIVE_OFF: /* disable receive to user space */
  420. if (dsp_debug & DEBUG_DSP_CORE)
  421. printk(KERN_DEBUG "%s: disable receive to "
  422. "user space\n", __func__);
  423. dsp->rx_disabled = 1;
  424. dsp_rx_off(dsp);
  425. break;
  426. case DSP_MIX_ON: /* enable mixing of tx data */
  427. if (dsp->hdlc) {
  428. ret = -EINVAL;
  429. break;
  430. }
  431. if (dsp_debug & DEBUG_DSP_CORE)
  432. printk(KERN_DEBUG "%s: enable mixing of "
  433. "tx-data with conf mebers\n", __func__);
  434. dsp->tx_mix = 1;
  435. dsp_cmx_hardware(dsp->conf, dsp);
  436. dsp_rx_off(dsp);
  437. if (dsp_debug & DEBUG_DSP_CMX)
  438. dsp_cmx_debug(dsp);
  439. break;
  440. case DSP_MIX_OFF: /* disable mixing of tx data */
  441. if (dsp->hdlc) {
  442. ret = -EINVAL;
  443. break;
  444. }
  445. if (dsp_debug & DEBUG_DSP_CORE)
  446. printk(KERN_DEBUG "%s: disable mixing of "
  447. "tx-data with conf mebers\n", __func__);
  448. dsp->tx_mix = 0;
  449. dsp_cmx_hardware(dsp->conf, dsp);
  450. dsp_rx_off(dsp);
  451. if (dsp_debug & DEBUG_DSP_CMX)
  452. dsp_cmx_debug(dsp);
  453. break;
  454. case DSP_TXDATA_ON: /* enable txdata */
  455. dsp->tx_data = 1;
  456. if (dsp_debug & DEBUG_DSP_CORE)
  457. printk(KERN_DEBUG "%s: enable tx-data\n", __func__);
  458. dsp_cmx_hardware(dsp->conf, dsp);
  459. dsp_rx_off(dsp);
  460. if (dsp_debug & DEBUG_DSP_CMX)
  461. dsp_cmx_debug(dsp);
  462. break;
  463. case DSP_TXDATA_OFF: /* disable txdata */
  464. dsp->tx_data = 0;
  465. if (dsp_debug & DEBUG_DSP_CORE)
  466. printk(KERN_DEBUG "%s: disable tx-data\n", __func__);
  467. dsp_cmx_hardware(dsp->conf, dsp);
  468. dsp_rx_off(dsp);
  469. if (dsp_debug & DEBUG_DSP_CMX)
  470. dsp_cmx_debug(dsp);
  471. break;
  472. case DSP_DELAY: /* use delay algorithm instead of dynamic
  473. jitter algorithm */
  474. if (dsp->hdlc) {
  475. ret = -EINVAL;
  476. break;
  477. }
  478. if (len < sizeof(int)) {
  479. ret = -EINVAL;
  480. break;
  481. }
  482. dsp->cmx_delay = (*((int *)data)) << 3;
  483. /* miliseconds to samples */
  484. if (dsp->cmx_delay >= (CMX_BUFF_HALF>>1))
  485. /* clip to half of maximum usable buffer
  486. (half of half buffer) */
  487. dsp->cmx_delay = (CMX_BUFF_HALF>>1) - 1;
  488. if (dsp_debug & DEBUG_DSP_CORE)
  489. printk(KERN_DEBUG "%s: use delay algorithm to "
  490. "compensate jitter (%d samples)\n",
  491. __func__, dsp->cmx_delay);
  492. break;
  493. case DSP_JITTER: /* use dynamic jitter algorithm instead of
  494. delay algorithm */
  495. if (dsp->hdlc) {
  496. ret = -EINVAL;
  497. break;
  498. }
  499. dsp->cmx_delay = 0;
  500. if (dsp_debug & DEBUG_DSP_CORE)
  501. printk(KERN_DEBUG "%s: use jitter algorithm to "
  502. "compensate jitter\n", __func__);
  503. break;
  504. case DSP_TX_DEJITTER: /* use dynamic jitter algorithm for tx-buffer */
  505. if (dsp->hdlc) {
  506. ret = -EINVAL;
  507. break;
  508. }
  509. dsp->tx_dejitter = 1;
  510. if (dsp_debug & DEBUG_DSP_CORE)
  511. printk(KERN_DEBUG "%s: use dejitter on TX "
  512. "buffer\n", __func__);
  513. break;
  514. case DSP_TX_DEJ_OFF: /* use tx-buffer without dejittering*/
  515. if (dsp->hdlc) {
  516. ret = -EINVAL;
  517. break;
  518. }
  519. dsp->tx_dejitter = 0;
  520. if (dsp_debug & DEBUG_DSP_CORE)
  521. printk(KERN_DEBUG "%s: use TX buffer without "
  522. "dejittering\n", __func__);
  523. break;
  524. case DSP_PIPELINE_CFG:
  525. if (dsp->hdlc) {
  526. ret = -EINVAL;
  527. break;
  528. }
  529. if (len > 0 && ((char *)data)[len - 1]) {
  530. printk(KERN_DEBUG "%s: pipeline config string "
  531. "is not NULL terminated!\n", __func__);
  532. ret = -EINVAL;
  533. } else {
  534. dsp->pipeline.inuse = 1;
  535. dsp_cmx_hardware(dsp->conf, dsp);
  536. ret = dsp_pipeline_build(&dsp->pipeline,
  537. len > 0 ? (char *)data : NULL);
  538. dsp_cmx_hardware(dsp->conf, dsp);
  539. dsp_rx_off(dsp);
  540. }
  541. break;
  542. case DSP_BF_ENABLE_KEY: /* turn blowfish on */
  543. if (dsp->hdlc) {
  544. ret = -EINVAL;
  545. break;
  546. }
  547. if (len < 4 || len > 56) {
  548. ret = -EINVAL;
  549. break;
  550. }
  551. if (dsp_debug & DEBUG_DSP_CORE)
  552. printk(KERN_DEBUG "%s: turn blowfish on (key "
  553. "not shown)\n", __func__);
  554. ret = dsp_bf_init(dsp, (u8 *)data, len);
  555. /* set new cont */
  556. if (!ret)
  557. cont = DSP_BF_ACCEPT;
  558. else
  559. cont = DSP_BF_REJECT;
  560. /* send indication if it worked to set it */
  561. nskb = _alloc_mISDN_skb(PH_CONTROL_IND, MISDN_ID_ANY,
  562. sizeof(int), &cont, GFP_ATOMIC);
  563. if (nskb) {
  564. if (dsp->up) {
  565. if (dsp->up->send(dsp->up, nskb))
  566. dev_kfree_skb(nskb);
  567. } else
  568. dev_kfree_skb(nskb);
  569. }
  570. if (!ret) {
  571. dsp_cmx_hardware(dsp->conf, dsp);
  572. dsp_dtmf_hardware(dsp);
  573. dsp_rx_off(dsp);
  574. }
  575. break;
  576. case DSP_BF_DISABLE: /* turn blowfish off */
  577. if (dsp->hdlc) {
  578. ret = -EINVAL;
  579. break;
  580. }
  581. if (dsp_debug & DEBUG_DSP_CORE)
  582. printk(KERN_DEBUG "%s: turn blowfish off\n", __func__);
  583. dsp_bf_cleanup(dsp);
  584. dsp_cmx_hardware(dsp->conf, dsp);
  585. dsp_dtmf_hardware(dsp);
  586. dsp_rx_off(dsp);
  587. break;
  588. default:
  589. if (dsp_debug & DEBUG_DSP_CORE)
  590. printk(KERN_DEBUG "%s: ctrl req %x unhandled\n",
  591. __func__, cont);
  592. ret = -EINVAL;
  593. }
  594. return ret;
  595. }
  596. static void
  597. get_features(struct mISDNchannel *ch)
  598. {
  599. struct dsp *dsp = container_of(ch, struct dsp, ch);
  600. struct mISDN_ctrl_req cq;
  601. if (!ch->peer) {
  602. if (dsp_debug & DEBUG_DSP_CORE)
  603. printk(KERN_DEBUG "%s: no peer, no features\n",
  604. __func__);
  605. return;
  606. }
  607. memset(&cq, 0, sizeof(cq));
  608. cq.op = MISDN_CTRL_GETOP;
  609. if (ch->peer->ctrl(ch->peer, CONTROL_CHANNEL, &cq) < 0) {
  610. printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n",
  611. __func__);
  612. return;
  613. }
  614. if (cq.op & MISDN_CTRL_RX_OFF)
  615. dsp->features_rx_off = 1;
  616. if (cq.op & MISDN_CTRL_FILL_EMPTY)
  617. dsp->features_fill_empty = 1;
  618. if (dsp_options & DSP_OPT_NOHARDWARE)
  619. return;
  620. if ((cq.op & MISDN_CTRL_HW_FEATURES_OP)) {
  621. cq.op = MISDN_CTRL_HW_FEATURES;
  622. *((u_long *)&cq.p1) = (u_long)&dsp->features;
  623. if (ch->peer->ctrl(ch->peer, CONTROL_CHANNEL, &cq)) {
  624. printk(KERN_DEBUG "%s: 2nd CONTROL_CHANNEL failed\n",
  625. __func__);
  626. }
  627. } else
  628. if (dsp_debug & DEBUG_DSP_CORE)
  629. printk(KERN_DEBUG "%s: features not supported for %s\n",
  630. __func__, dsp->name);
  631. }
  632. static int
  633. dsp_function(struct mISDNchannel *ch, struct sk_buff *skb)
  634. {
  635. struct dsp *dsp = container_of(ch, struct dsp, ch);
  636. struct mISDNhead *hh;
  637. int ret = 0;
  638. u8 *digits;
  639. int cont;
  640. u_long flags;
  641. hh = mISDN_HEAD_P(skb);
  642. switch (hh->prim) {
  643. /* FROM DOWN */
  644. case (PH_DATA_CNF):
  645. dsp->data_pending = 0;
  646. /* trigger next hdlc frame, if any */
  647. if (dsp->hdlc) {
  648. spin_lock_irqsave(&dsp_lock, flags);
  649. if (dsp->b_active)
  650. schedule_work(&dsp->workq);
  651. spin_unlock_irqrestore(&dsp_lock, flags);
  652. }
  653. break;
  654. case (PH_DATA_IND):
  655. case (DL_DATA_IND):
  656. if (skb->len < 1) {
  657. ret = -EINVAL;
  658. break;
  659. }
  660. if (dsp->rx_is_off) {
  661. if (dsp_debug & DEBUG_DSP_CORE)
  662. printk(KERN_DEBUG "%s: rx-data during rx_off"
  663. " for %s\n",
  664. __func__, dsp->name);
  665. }
  666. if (dsp->hdlc) {
  667. /* hdlc */
  668. spin_lock_irqsave(&dsp_lock, flags);
  669. dsp_cmx_hdlc(dsp, skb);
  670. spin_unlock_irqrestore(&dsp_lock, flags);
  671. if (dsp->rx_disabled) {
  672. /* if receive is not allowed */
  673. break;
  674. }
  675. hh->prim = DL_DATA_IND;
  676. if (dsp->up)
  677. return dsp->up->send(dsp->up, skb);
  678. break;
  679. }
  680. /* decrypt if enabled */
  681. if (dsp->bf_enable)
  682. dsp_bf_decrypt(dsp, skb->data, skb->len);
  683. /* pipeline */
  684. if (dsp->pipeline.inuse)
  685. dsp_pipeline_process_rx(&dsp->pipeline, skb->data,
  686. skb->len);
  687. /* change volume if requested */
  688. if (dsp->rx_volume)
  689. dsp_change_volume(skb, dsp->rx_volume);
  690. /* check if dtmf soft decoding is turned on */
  691. if (dsp->dtmf.software) {
  692. digits = dsp_dtmf_goertzel_decode(dsp, skb->data,
  693. skb->len, (dsp_options&DSP_OPT_ULAW)?1:0);
  694. while (*digits) {
  695. struct sk_buff *nskb;
  696. if (dsp_debug & DEBUG_DSP_DTMF)
  697. printk(KERN_DEBUG "%s: digit"
  698. "(%c) to layer %s\n",
  699. __func__, *digits, dsp->name);
  700. cont = DTMF_TONE_VAL | *digits;
  701. nskb = _alloc_mISDN_skb(PH_CONTROL_IND,
  702. MISDN_ID_ANY, sizeof(int), &cont,
  703. GFP_ATOMIC);
  704. if (nskb) {
  705. if (dsp->up) {
  706. if (dsp->up->send(
  707. dsp->up, nskb))
  708. dev_kfree_skb(nskb);
  709. } else
  710. dev_kfree_skb(nskb);
  711. }
  712. digits++;
  713. }
  714. }
  715. /* we need to process receive data if software */
  716. spin_lock_irqsave(&dsp_lock, flags);
  717. if (dsp->pcm_slot_tx < 0 && dsp->pcm_slot_rx < 0) {
  718. /* process data from card at cmx */
  719. dsp_cmx_receive(dsp, skb);
  720. }
  721. spin_unlock_irqrestore(&dsp_lock, flags);
  722. if (dsp->rx_disabled) {
  723. /* if receive is not allowed */
  724. break;
  725. }
  726. hh->prim = DL_DATA_IND;
  727. if (dsp->up)
  728. return dsp->up->send(dsp->up, skb);
  729. break;
  730. case (PH_CONTROL_IND):
  731. if (dsp_debug & DEBUG_DSP_DTMFCOEFF)
  732. printk(KERN_DEBUG "%s: PH_CONTROL INDICATION "
  733. "received: %x (len %d) %s\n", __func__,
  734. hh->id, skb->len, dsp->name);
  735. switch (hh->id) {
  736. case (DTMF_HFC_COEF): /* getting coefficients */
  737. if (!dsp->dtmf.hardware) {
  738. if (dsp_debug & DEBUG_DSP_DTMFCOEFF)
  739. printk(KERN_DEBUG "%s: ignoring DTMF "
  740. "coefficients from HFC\n",
  741. __func__);
  742. break;
  743. }
  744. digits = dsp_dtmf_goertzel_decode(dsp, skb->data,
  745. skb->len, 2);
  746. while (*digits) {
  747. int k;
  748. struct sk_buff *nskb;
  749. if (dsp_debug & DEBUG_DSP_DTMF)
  750. printk(KERN_DEBUG "%s: digit"
  751. "(%c) to layer %s\n",
  752. __func__, *digits, dsp->name);
  753. k = *digits | DTMF_TONE_VAL;
  754. nskb = _alloc_mISDN_skb(PH_CONTROL_IND,
  755. MISDN_ID_ANY, sizeof(int), &k,
  756. GFP_ATOMIC);
  757. if (nskb) {
  758. if (dsp->up) {
  759. if (dsp->up->send(
  760. dsp->up, nskb))
  761. dev_kfree_skb(nskb);
  762. } else
  763. dev_kfree_skb(nskb);
  764. }
  765. digits++;
  766. }
  767. break;
  768. case (HFC_VOL_CHANGE_TX): /* change volume */
  769. if (skb->len != sizeof(int)) {
  770. ret = -EINVAL;
  771. break;
  772. }
  773. spin_lock_irqsave(&dsp_lock, flags);
  774. dsp->tx_volume = *((int *)skb->data);
  775. if (dsp_debug & DEBUG_DSP_CORE)
  776. printk(KERN_DEBUG "%s: change tx volume to "
  777. "%d\n", __func__, dsp->tx_volume);
  778. dsp_cmx_hardware(dsp->conf, dsp);
  779. dsp_dtmf_hardware(dsp);
  780. dsp_rx_off(dsp);
  781. spin_unlock_irqrestore(&dsp_lock, flags);
  782. break;
  783. default:
  784. if (dsp_debug & DEBUG_DSP_CORE)
  785. printk(KERN_DEBUG "%s: ctrl ind %x unhandled "
  786. "%s\n", __func__, hh->id, dsp->name);
  787. ret = -EINVAL;
  788. }
  789. break;
  790. case (PH_ACTIVATE_IND):
  791. case (PH_ACTIVATE_CNF):
  792. if (dsp_debug & DEBUG_DSP_CORE)
  793. printk(KERN_DEBUG "%s: b_channel is now active %s\n",
  794. __func__, dsp->name);
  795. /* bchannel now active */
  796. spin_lock_irqsave(&dsp_lock, flags);
  797. dsp->b_active = 1;
  798. dsp->data_pending = 0;
  799. dsp->rx_init = 1;
  800. /* rx_W and rx_R will be adjusted on first frame */
  801. dsp->rx_W = 0;
  802. dsp->rx_R = 0;
  803. memset(dsp->rx_buff, 0, sizeof(dsp->rx_buff));
  804. dsp_cmx_hardware(dsp->conf, dsp);
  805. dsp_dtmf_hardware(dsp);
  806. dsp_rx_off(dsp);
  807. spin_unlock_irqrestore(&dsp_lock, flags);
  808. if (dsp_debug & DEBUG_DSP_CORE)
  809. printk(KERN_DEBUG "%s: done with activation, sending "
  810. "confirm to user space. %s\n", __func__,
  811. dsp->name);
  812. /* send activation to upper layer */
  813. hh->prim = DL_ESTABLISH_CNF;
  814. if (dsp->up)
  815. return dsp->up->send(dsp->up, skb);
  816. break;
  817. case (PH_DEACTIVATE_IND):
  818. case (PH_DEACTIVATE_CNF):
  819. if (dsp_debug & DEBUG_DSP_CORE)
  820. printk(KERN_DEBUG "%s: b_channel is now inactive %s\n",
  821. __func__, dsp->name);
  822. /* bchannel now inactive */
  823. spin_lock_irqsave(&dsp_lock, flags);
  824. dsp->b_active = 0;
  825. dsp->data_pending = 0;
  826. dsp_cmx_hardware(dsp->conf, dsp);
  827. dsp_rx_off(dsp);
  828. spin_unlock_irqrestore(&dsp_lock, flags);
  829. hh->prim = DL_RELEASE_CNF;
  830. if (dsp->up)
  831. return dsp->up->send(dsp->up, skb);
  832. break;
  833. /* FROM UP */
  834. case (DL_DATA_REQ):
  835. case (PH_DATA_REQ):
  836. if (skb->len < 1) {
  837. ret = -EINVAL;
  838. break;
  839. }
  840. if (dsp->hdlc) {
  841. /* hdlc */
  842. if (!dsp->b_active) {
  843. ret = -EIO;
  844. break;
  845. }
  846. hh->prim = PH_DATA_REQ;
  847. spin_lock_irqsave(&dsp_lock, flags);
  848. skb_queue_tail(&dsp->sendq, skb);
  849. schedule_work(&dsp->workq);
  850. spin_unlock_irqrestore(&dsp_lock, flags);
  851. return 0;
  852. }
  853. /* send data to tx-buffer (if no tone is played) */
  854. if (!dsp->tone.tone) {
  855. spin_lock_irqsave(&dsp_lock, flags);
  856. dsp_cmx_transmit(dsp, skb);
  857. spin_unlock_irqrestore(&dsp_lock, flags);
  858. }
  859. break;
  860. case (PH_CONTROL_REQ):
  861. spin_lock_irqsave(&dsp_lock, flags);
  862. ret = dsp_control_req(dsp, hh, skb);
  863. spin_unlock_irqrestore(&dsp_lock, flags);
  864. break;
  865. case (DL_ESTABLISH_REQ):
  866. case (PH_ACTIVATE_REQ):
  867. if (dsp_debug & DEBUG_DSP_CORE)
  868. printk(KERN_DEBUG "%s: activating b_channel %s\n",
  869. __func__, dsp->name);
  870. if (dsp->dtmf.hardware || dsp->dtmf.software)
  871. dsp_dtmf_goertzel_init(dsp);
  872. get_features(ch);
  873. /* enable fill_empty feature */
  874. if (dsp->features_fill_empty)
  875. dsp_fill_empty(dsp);
  876. /* send ph_activate */
  877. hh->prim = PH_ACTIVATE_REQ;
  878. if (ch->peer)
  879. return ch->recv(ch->peer, skb);
  880. break;
  881. case (DL_RELEASE_REQ):
  882. case (PH_DEACTIVATE_REQ):
  883. if (dsp_debug & DEBUG_DSP_CORE)
  884. printk(KERN_DEBUG "%s: releasing b_channel %s\n",
  885. __func__, dsp->name);
  886. spin_lock_irqsave(&dsp_lock, flags);
  887. dsp->tone.tone = 0;
  888. dsp->tone.hardware = 0;
  889. dsp->tone.software = 0;
  890. if (timer_pending(&dsp->tone.tl))
  891. del_timer(&dsp->tone.tl);
  892. if (dsp->conf)
  893. dsp_cmx_conf(dsp, 0); /* dsp_cmx_hardware will also be
  894. called here */
  895. skb_queue_purge(&dsp->sendq);
  896. spin_unlock_irqrestore(&dsp_lock, flags);
  897. hh->prim = PH_DEACTIVATE_REQ;
  898. if (ch->peer)
  899. return ch->recv(ch->peer, skb);
  900. break;
  901. default:
  902. if (dsp_debug & DEBUG_DSP_CORE)
  903. printk(KERN_DEBUG "%s: msg %x unhandled %s\n",
  904. __func__, hh->prim, dsp->name);
  905. ret = -EINVAL;
  906. }
  907. if (!ret)
  908. dev_kfree_skb(skb);
  909. return ret;
  910. }
  911. static int
  912. dsp_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
  913. {
  914. struct dsp *dsp = container_of(ch, struct dsp, ch);
  915. u_long flags;
  916. int err = 0;
  917. if (debug & DEBUG_DSP_CTRL)
  918. printk(KERN_DEBUG "%s:(%x)\n", __func__, cmd);
  919. switch (cmd) {
  920. case OPEN_CHANNEL:
  921. break;
  922. case CLOSE_CHANNEL:
  923. if (dsp->ch.peer)
  924. dsp->ch.peer->ctrl(dsp->ch.peer, CLOSE_CHANNEL, NULL);
  925. /* wait until workqueue has finished,
  926. * must lock here, or we may hit send-process currently
  927. * queueing. */
  928. spin_lock_irqsave(&dsp_lock, flags);
  929. dsp->b_active = 0;
  930. spin_unlock_irqrestore(&dsp_lock, flags);
  931. /* MUST not be locked, because it waits until queue is done. */
  932. cancel_work_sync(&dsp->workq);
  933. spin_lock_irqsave(&dsp_lock, flags);
  934. if (timer_pending(&dsp->tone.tl))
  935. del_timer(&dsp->tone.tl);
  936. skb_queue_purge(&dsp->sendq);
  937. if (dsp_debug & DEBUG_DSP_CTRL)
  938. printk(KERN_DEBUG "%s: releasing member %s\n",
  939. __func__, dsp->name);
  940. dsp->b_active = 0;
  941. dsp_cmx_conf(dsp, 0); /* dsp_cmx_hardware will also be called
  942. here */
  943. dsp_pipeline_destroy(&dsp->pipeline);
  944. if (dsp_debug & DEBUG_DSP_CTRL)
  945. printk(KERN_DEBUG "%s: remove & destroy object %s\n",
  946. __func__, dsp->name);
  947. list_del(&dsp->list);
  948. spin_unlock_irqrestore(&dsp_lock, flags);
  949. if (dsp_debug & DEBUG_DSP_CTRL)
  950. printk(KERN_DEBUG "%s: dsp instance released\n",
  951. __func__);
  952. vfree(dsp);
  953. module_put(THIS_MODULE);
  954. break;
  955. }
  956. return err;
  957. }
  958. static void
  959. dsp_send_bh(struct work_struct *work)
  960. {
  961. struct dsp *dsp = container_of(work, struct dsp, workq);
  962. struct sk_buff *skb;
  963. struct mISDNhead *hh;
  964. if (dsp->hdlc && dsp->data_pending)
  965. return; /* wait until data has been acknowledged */
  966. /* send queued data */
  967. while ((skb = skb_dequeue(&dsp->sendq))) {
  968. /* in locked date, we must have still data in queue */
  969. if (dsp->data_pending) {
  970. if (dsp_debug & DEBUG_DSP_CORE)
  971. printk(KERN_DEBUG "%s: fifo full %s, this is "
  972. "no bug!\n", __func__, dsp->name);
  973. /* flush transparent data, if not acked */
  974. dev_kfree_skb(skb);
  975. continue;
  976. }
  977. hh = mISDN_HEAD_P(skb);
  978. if (hh->prim == DL_DATA_REQ) {
  979. /* send packet up */
  980. if (dsp->up) {
  981. if (dsp->up->send(dsp->up, skb))
  982. dev_kfree_skb(skb);
  983. } else
  984. dev_kfree_skb(skb);
  985. } else {
  986. /* send packet down */
  987. if (dsp->ch.peer) {
  988. dsp->data_pending = 1;
  989. if (dsp->ch.recv(dsp->ch.peer, skb)) {
  990. dev_kfree_skb(skb);
  991. dsp->data_pending = 0;
  992. }
  993. } else
  994. dev_kfree_skb(skb);
  995. }
  996. }
  997. }
  998. static int
  999. dspcreate(struct channel_req *crq)
  1000. {
  1001. struct dsp *ndsp;
  1002. u_long flags;
  1003. if (crq->protocol != ISDN_P_B_L2DSP
  1004. && crq->protocol != ISDN_P_B_L2DSPHDLC)
  1005. return -EPROTONOSUPPORT;
  1006. ndsp = vmalloc(sizeof(struct dsp));
  1007. if (!ndsp) {
  1008. printk(KERN_ERR "%s: vmalloc struct dsp failed\n", __func__);
  1009. return -ENOMEM;
  1010. }
  1011. memset(ndsp, 0, sizeof(struct dsp));
  1012. if (dsp_debug & DEBUG_DSP_CTRL)
  1013. printk(KERN_DEBUG "%s: creating new dsp instance\n", __func__);
  1014. /* default enabled */
  1015. INIT_WORK(&ndsp->workq, (void *)dsp_send_bh);
  1016. skb_queue_head_init(&ndsp->sendq);
  1017. ndsp->ch.send = dsp_function;
  1018. ndsp->ch.ctrl = dsp_ctrl;
  1019. ndsp->up = crq->ch;
  1020. crq->ch = &ndsp->ch;
  1021. if (crq->protocol == ISDN_P_B_L2DSP) {
  1022. crq->protocol = ISDN_P_B_RAW;
  1023. ndsp->hdlc = 0;
  1024. } else {
  1025. crq->protocol = ISDN_P_B_HDLC;
  1026. ndsp->hdlc = 1;
  1027. }
  1028. if (!try_module_get(THIS_MODULE))
  1029. printk(KERN_WARNING "%s:cannot get module\n",
  1030. __func__);
  1031. sprintf(ndsp->name, "DSP_C%x(0x%p)",
  1032. ndsp->up->st->dev->id + 1, ndsp);
  1033. /* set frame size to start */
  1034. ndsp->features.hfc_id = -1; /* current PCM id */
  1035. ndsp->features.pcm_id = -1; /* current PCM id */
  1036. ndsp->pcm_slot_rx = -1; /* current CPM slot */
  1037. ndsp->pcm_slot_tx = -1;
  1038. ndsp->pcm_bank_rx = -1;
  1039. ndsp->pcm_bank_tx = -1;
  1040. ndsp->hfc_conf = -1; /* current conference number */
  1041. /* set tone timer */
  1042. ndsp->tone.tl.function = (void *)dsp_tone_timeout;
  1043. ndsp->tone.tl.data = (long) ndsp;
  1044. init_timer(&ndsp->tone.tl);
  1045. if (dtmfthreshold < 20 || dtmfthreshold > 500)
  1046. dtmfthreshold = 200;
  1047. ndsp->dtmf.treshold = dtmfthreshold*10000;
  1048. /* init pipeline append to list */
  1049. spin_lock_irqsave(&dsp_lock, flags);
  1050. dsp_pipeline_init(&ndsp->pipeline);
  1051. list_add_tail(&ndsp->list, &dsp_ilist);
  1052. spin_unlock_irqrestore(&dsp_lock, flags);
  1053. return 0;
  1054. }
  1055. static struct Bprotocol DSP = {
  1056. .Bprotocols = (1 << (ISDN_P_B_L2DSP & ISDN_P_B_MASK))
  1057. | (1 << (ISDN_P_B_L2DSPHDLC & ISDN_P_B_MASK)),
  1058. .name = "dsp",
  1059. .create = dspcreate
  1060. };
  1061. static int dsp_init(void)
  1062. {
  1063. int err;
  1064. int tics;
  1065. printk(KERN_INFO "DSP modul %s\n", mISDN_dsp_revision);
  1066. dsp_options = options;
  1067. dsp_debug = debug;
  1068. /* set packet size */
  1069. dsp_poll = poll;
  1070. if (dsp_poll) {
  1071. if (dsp_poll > MAX_POLL) {
  1072. printk(KERN_ERR "%s: Wrong poll value (%d), use %d "
  1073. "maximum.\n", __func__, poll, MAX_POLL);
  1074. err = -EINVAL;
  1075. return err;
  1076. }
  1077. if (dsp_poll < 8) {
  1078. printk(KERN_ERR "%s: Wrong poll value (%d), use 8 "
  1079. "minimum.\n", __func__, dsp_poll);
  1080. err = -EINVAL;
  1081. return err;
  1082. }
  1083. dsp_tics = poll * HZ / 8000;
  1084. if (dsp_tics * 8000 != poll * HZ) {
  1085. printk(KERN_INFO "mISDN_dsp: Cannot clock every %d "
  1086. "samples (0,125 ms). It is not a multiple of "
  1087. "%d HZ.\n", poll, HZ);
  1088. err = -EINVAL;
  1089. return err;
  1090. }
  1091. } else {
  1092. poll = 8;
  1093. while (poll <= MAX_POLL) {
  1094. tics = (poll * HZ) / 8000;
  1095. if (tics * 8000 == poll * HZ) {
  1096. dsp_tics = tics;
  1097. dsp_poll = poll;
  1098. if (poll >= 64)
  1099. break;
  1100. }
  1101. poll++;
  1102. }
  1103. }
  1104. if (dsp_poll == 0) {
  1105. printk(KERN_INFO "mISDN_dsp: There is no multiple of kernel "
  1106. "clock that equals exactly the duration of 8-256 "
  1107. "samples. (Choose kernel clock speed like 100, 250, "
  1108. "300, 1000)\n");
  1109. err = -EINVAL;
  1110. return err;
  1111. }
  1112. printk(KERN_INFO "mISDN_dsp: DSP clocks every %d samples. This equals "
  1113. "%d jiffies.\n", dsp_poll, dsp_tics);
  1114. spin_lock_init(&dsp_lock);
  1115. INIT_LIST_HEAD(&dsp_ilist);
  1116. INIT_LIST_HEAD(&conf_ilist);
  1117. /* init conversion tables */
  1118. dsp_audio_generate_law_tables();
  1119. dsp_silence = (dsp_options&DSP_OPT_ULAW)?0xff:0x2a;
  1120. dsp_audio_law_to_s32 = (dsp_options&DSP_OPT_ULAW)?dsp_audio_ulaw_to_s32:
  1121. dsp_audio_alaw_to_s32;
  1122. dsp_audio_generate_s2law_table();
  1123. dsp_audio_generate_seven();
  1124. dsp_audio_generate_mix_table();
  1125. if (dsp_options & DSP_OPT_ULAW)
  1126. dsp_audio_generate_ulaw_samples();
  1127. dsp_audio_generate_volume_changes();
  1128. err = dsp_pipeline_module_init();
  1129. if (err) {
  1130. printk(KERN_ERR "mISDN_dsp: Can't initialize pipeline, "
  1131. "error(%d)\n", err);
  1132. return err;
  1133. }
  1134. err = mISDN_register_Bprotocol(&DSP);
  1135. if (err) {
  1136. printk(KERN_ERR "Can't register %s error(%d)\n", DSP.name, err);
  1137. return err;
  1138. }
  1139. /* set sample timer */
  1140. dsp_spl_tl.function = (void *)dsp_cmx_send;
  1141. dsp_spl_tl.data = 0;
  1142. init_timer(&dsp_spl_tl);
  1143. dsp_spl_tl.expires = jiffies + dsp_tics;
  1144. dsp_spl_jiffies = dsp_spl_tl.expires;
  1145. add_timer(&dsp_spl_tl);
  1146. return 0;
  1147. }
  1148. static void dsp_cleanup(void)
  1149. {
  1150. mISDN_unregister_Bprotocol(&DSP);
  1151. if (timer_pending(&dsp_spl_tl))
  1152. del_timer(&dsp_spl_tl);
  1153. if (!list_empty(&dsp_ilist)) {
  1154. printk(KERN_ERR "mISDN_dsp: Audio DSP object inst list not "
  1155. "empty.\n");
  1156. }
  1157. if (!list_empty(&conf_ilist)) {
  1158. printk(KERN_ERR "mISDN_dsp: Conference list not empty. Not "
  1159. "all memory freed.\n");
  1160. }
  1161. dsp_pipeline_module_exit();
  1162. }
  1163. module_init(dsp_init);
  1164. module_exit(dsp_cleanup);