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