dsp_core.c 33 KB

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