dsp_core.c 33 KB

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