dsp_core.c 32 KB

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