dsp_core.c 32 KB

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