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 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.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. 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. if (dsp_debug & DEBUG_DSP_CORE)
  284. printk(KERN_NOTICE "changing DTMF Threshold "
  285. "to %d\n", *((int *)data));
  286. dsp->dtmf.treshold = (*(int *)data) * 10000;
  287. }
  288. dsp->dtmf.enable = 1;
  289. /* init goertzel */
  290. dsp_dtmf_goertzel_init(dsp);
  291. /* check dtmf hardware */
  292. dsp_dtmf_hardware(dsp);
  293. dsp_rx_off(dsp);
  294. break;
  295. case DTMF_TONE_STOP: /* turn off DTMF */
  296. if (dsp_debug & DEBUG_DSP_CORE)
  297. printk(KERN_DEBUG "%s: stop dtmf\n", __func__);
  298. dsp->dtmf.enable = 0;
  299. dsp->dtmf.hardware = 0;
  300. dsp->dtmf.software = 0;
  301. break;
  302. case DSP_CONF_JOIN: /* join / update conference */
  303. if (len < sizeof(int)) {
  304. ret = -EINVAL;
  305. break;
  306. }
  307. if (*((u32 *)data) == 0)
  308. goto conf_split;
  309. if (dsp_debug & DEBUG_DSP_CORE)
  310. printk(KERN_DEBUG "%s: join conference %d\n",
  311. __func__, *((u32 *)data));
  312. ret = dsp_cmx_conf(dsp, *((u32 *)data));
  313. /* dsp_cmx_hardware will also be called here */
  314. dsp_rx_off(dsp);
  315. if (dsp_debug & DEBUG_DSP_CMX)
  316. dsp_cmx_debug(dsp);
  317. break;
  318. case DSP_CONF_SPLIT: /* remove from conference */
  319. conf_split:
  320. if (dsp_debug & DEBUG_DSP_CORE)
  321. printk(KERN_DEBUG "%s: release conference\n", __func__);
  322. ret = dsp_cmx_conf(dsp, 0);
  323. /* dsp_cmx_hardware will also be called here */
  324. if (dsp_debug & DEBUG_DSP_CMX)
  325. dsp_cmx_debug(dsp);
  326. dsp_rx_off(dsp);
  327. break;
  328. case DSP_TONE_PATT_ON: /* play tone */
  329. if (dsp->hdlc) {
  330. ret = -EINVAL;
  331. break;
  332. }
  333. if (len < sizeof(int)) {
  334. ret = -EINVAL;
  335. break;
  336. }
  337. if (dsp_debug & DEBUG_DSP_CORE)
  338. printk(KERN_DEBUG "%s: turn tone 0x%x on\n",
  339. __func__, *((int *)skb->data));
  340. ret = dsp_tone(dsp, *((int *)data));
  341. if (!ret) {
  342. dsp_cmx_hardware(dsp->conf, dsp);
  343. dsp_rx_off(dsp);
  344. }
  345. if (!dsp->tone.tone)
  346. goto tone_off;
  347. break;
  348. case DSP_TONE_PATT_OFF: /* stop tone */
  349. if (dsp->hdlc) {
  350. ret = -EINVAL;
  351. break;
  352. }
  353. if (dsp_debug & DEBUG_DSP_CORE)
  354. printk(KERN_DEBUG "%s: turn tone off\n", __func__);
  355. dsp_tone(dsp, 0);
  356. dsp_cmx_hardware(dsp->conf, dsp);
  357. dsp_rx_off(dsp);
  358. /* reset tx buffers (user space data) */
  359. tone_off:
  360. dsp->rx_W = 0;
  361. dsp->rx_R = 0;
  362. break;
  363. case DSP_VOL_CHANGE_TX: /* change volume */
  364. if (dsp->hdlc) {
  365. ret = -EINVAL;
  366. break;
  367. }
  368. if (len < sizeof(int)) {
  369. ret = -EINVAL;
  370. break;
  371. }
  372. dsp->tx_volume = *((int *)data);
  373. if (dsp_debug & DEBUG_DSP_CORE)
  374. printk(KERN_DEBUG "%s: change tx vol to %d\n",
  375. __func__, dsp->tx_volume);
  376. dsp_cmx_hardware(dsp->conf, dsp);
  377. dsp_dtmf_hardware(dsp);
  378. dsp_rx_off(dsp);
  379. break;
  380. case DSP_VOL_CHANGE_RX: /* change volume */
  381. if (dsp->hdlc) {
  382. ret = -EINVAL;
  383. break;
  384. }
  385. if (len < sizeof(int)) {
  386. ret = -EINVAL;
  387. break;
  388. }
  389. dsp->rx_volume = *((int *)data);
  390. if (dsp_debug & DEBUG_DSP_CORE)
  391. printk(KERN_DEBUG "%s: change rx vol to %d\n",
  392. __func__, dsp->tx_volume);
  393. dsp_cmx_hardware(dsp->conf, dsp);
  394. dsp_dtmf_hardware(dsp);
  395. dsp_rx_off(dsp);
  396. break;
  397. case DSP_ECHO_ON: /* enable echo */
  398. dsp->echo.software = 1; /* soft echo */
  399. if (dsp_debug & DEBUG_DSP_CORE)
  400. printk(KERN_DEBUG "%s: enable cmx-echo\n", __func__);
  401. dsp_cmx_hardware(dsp->conf, dsp);
  402. dsp_rx_off(dsp);
  403. if (dsp_debug & DEBUG_DSP_CMX)
  404. dsp_cmx_debug(dsp);
  405. break;
  406. case DSP_ECHO_OFF: /* disable echo */
  407. dsp->echo.software = 0;
  408. dsp->echo.hardware = 0;
  409. if (dsp_debug & DEBUG_DSP_CORE)
  410. printk(KERN_DEBUG "%s: disable cmx-echo\n", __func__);
  411. dsp_cmx_hardware(dsp->conf, dsp);
  412. dsp_rx_off(dsp);
  413. if (dsp_debug & DEBUG_DSP_CMX)
  414. dsp_cmx_debug(dsp);
  415. break;
  416. case DSP_RECEIVE_ON: /* enable receive to user space */
  417. if (dsp_debug & DEBUG_DSP_CORE)
  418. printk(KERN_DEBUG "%s: enable receive to user "
  419. "space\n", __func__);
  420. dsp->rx_disabled = 0;
  421. dsp_rx_off(dsp);
  422. break;
  423. case DSP_RECEIVE_OFF: /* disable receive to user space */
  424. if (dsp_debug & DEBUG_DSP_CORE)
  425. printk(KERN_DEBUG "%s: disable receive to "
  426. "user space\n", __func__);
  427. dsp->rx_disabled = 1;
  428. dsp_rx_off(dsp);
  429. break;
  430. case DSP_MIX_ON: /* enable mixing of tx data */
  431. if (dsp->hdlc) {
  432. ret = -EINVAL;
  433. break;
  434. }
  435. if (dsp_debug & DEBUG_DSP_CORE)
  436. printk(KERN_DEBUG "%s: enable mixing of "
  437. "tx-data with conf mebers\n", __func__);
  438. dsp->tx_mix = 1;
  439. dsp_cmx_hardware(dsp->conf, dsp);
  440. dsp_rx_off(dsp);
  441. if (dsp_debug & DEBUG_DSP_CMX)
  442. dsp_cmx_debug(dsp);
  443. break;
  444. case DSP_MIX_OFF: /* disable mixing of tx data */
  445. if (dsp->hdlc) {
  446. ret = -EINVAL;
  447. break;
  448. }
  449. if (dsp_debug & DEBUG_DSP_CORE)
  450. printk(KERN_DEBUG "%s: disable mixing of "
  451. "tx-data with conf mebers\n", __func__);
  452. dsp->tx_mix = 0;
  453. dsp_cmx_hardware(dsp->conf, dsp);
  454. dsp_rx_off(dsp);
  455. if (dsp_debug & DEBUG_DSP_CMX)
  456. dsp_cmx_debug(dsp);
  457. break;
  458. case DSP_TXDATA_ON: /* enable txdata */
  459. dsp->tx_data = 1;
  460. if (dsp_debug & DEBUG_DSP_CORE)
  461. printk(KERN_DEBUG "%s: enable tx-data\n", __func__);
  462. dsp_cmx_hardware(dsp->conf, dsp);
  463. dsp_rx_off(dsp);
  464. if (dsp_debug & DEBUG_DSP_CMX)
  465. dsp_cmx_debug(dsp);
  466. break;
  467. case DSP_TXDATA_OFF: /* disable txdata */
  468. dsp->tx_data = 0;
  469. if (dsp_debug & DEBUG_DSP_CORE)
  470. printk(KERN_DEBUG "%s: disable tx-data\n", __func__);
  471. dsp_cmx_hardware(dsp->conf, dsp);
  472. dsp_rx_off(dsp);
  473. if (dsp_debug & DEBUG_DSP_CMX)
  474. dsp_cmx_debug(dsp);
  475. break;
  476. case DSP_DELAY: /* use delay algorithm instead of dynamic
  477. jitter algorithm */
  478. if (dsp->hdlc) {
  479. ret = -EINVAL;
  480. break;
  481. }
  482. if (len < sizeof(int)) {
  483. ret = -EINVAL;
  484. break;
  485. }
  486. dsp->cmx_delay = (*((int *)data)) << 3;
  487. /* milliseconds to samples */
  488. if (dsp->cmx_delay >= (CMX_BUFF_HALF>>1))
  489. /* clip to half of maximum usable buffer
  490. (half of half buffer) */
  491. dsp->cmx_delay = (CMX_BUFF_HALF>>1) - 1;
  492. if (dsp_debug & DEBUG_DSP_CORE)
  493. printk(KERN_DEBUG "%s: use delay algorithm to "
  494. "compensate jitter (%d samples)\n",
  495. __func__, dsp->cmx_delay);
  496. break;
  497. case DSP_JITTER: /* use dynamic jitter algorithm instead of
  498. delay algorithm */
  499. if (dsp->hdlc) {
  500. ret = -EINVAL;
  501. break;
  502. }
  503. dsp->cmx_delay = 0;
  504. if (dsp_debug & DEBUG_DSP_CORE)
  505. printk(KERN_DEBUG "%s: use jitter algorithm to "
  506. "compensate jitter\n", __func__);
  507. break;
  508. case DSP_TX_DEJITTER: /* use dynamic jitter algorithm for tx-buffer */
  509. if (dsp->hdlc) {
  510. ret = -EINVAL;
  511. break;
  512. }
  513. dsp->tx_dejitter = 1;
  514. if (dsp_debug & DEBUG_DSP_CORE)
  515. printk(KERN_DEBUG "%s: use dejitter on TX "
  516. "buffer\n", __func__);
  517. break;
  518. case DSP_TX_DEJ_OFF: /* use tx-buffer without dejittering*/
  519. if (dsp->hdlc) {
  520. ret = -EINVAL;
  521. break;
  522. }
  523. dsp->tx_dejitter = 0;
  524. if (dsp_debug & DEBUG_DSP_CORE)
  525. printk(KERN_DEBUG "%s: use TX buffer without "
  526. "dejittering\n", __func__);
  527. break;
  528. case DSP_PIPELINE_CFG:
  529. if (dsp->hdlc) {
  530. ret = -EINVAL;
  531. break;
  532. }
  533. if (len > 0 && ((char *)data)[len - 1]) {
  534. printk(KERN_DEBUG "%s: pipeline config string "
  535. "is not NULL terminated!\n", __func__);
  536. ret = -EINVAL;
  537. } else {
  538. dsp->pipeline.inuse = 1;
  539. dsp_cmx_hardware(dsp->conf, dsp);
  540. ret = dsp_pipeline_build(&dsp->pipeline,
  541. len > 0 ? data : NULL);
  542. dsp_cmx_hardware(dsp->conf, dsp);
  543. dsp_rx_off(dsp);
  544. }
  545. break;
  546. case DSP_BF_ENABLE_KEY: /* turn blowfish on */
  547. if (dsp->hdlc) {
  548. ret = -EINVAL;
  549. break;
  550. }
  551. if (len < 4 || len > 56) {
  552. ret = -EINVAL;
  553. break;
  554. }
  555. if (dsp_debug & DEBUG_DSP_CORE)
  556. printk(KERN_DEBUG "%s: turn blowfish on (key "
  557. "not shown)\n", __func__);
  558. ret = dsp_bf_init(dsp, (u8 *)data, len);
  559. /* set new cont */
  560. if (!ret)
  561. cont = DSP_BF_ACCEPT;
  562. else
  563. cont = DSP_BF_REJECT;
  564. /* send indication if it worked to set it */
  565. nskb = _alloc_mISDN_skb(PH_CONTROL_IND, MISDN_ID_ANY,
  566. sizeof(int), &cont, GFP_ATOMIC);
  567. if (nskb) {
  568. if (dsp->up) {
  569. if (dsp->up->send(dsp->up, nskb))
  570. dev_kfree_skb(nskb);
  571. } else
  572. dev_kfree_skb(nskb);
  573. }
  574. if (!ret) {
  575. dsp_cmx_hardware(dsp->conf, dsp);
  576. dsp_dtmf_hardware(dsp);
  577. dsp_rx_off(dsp);
  578. }
  579. break;
  580. case DSP_BF_DISABLE: /* turn blowfish off */
  581. if (dsp->hdlc) {
  582. ret = -EINVAL;
  583. break;
  584. }
  585. if (dsp_debug & DEBUG_DSP_CORE)
  586. printk(KERN_DEBUG "%s: turn blowfish off\n", __func__);
  587. dsp_bf_cleanup(dsp);
  588. dsp_cmx_hardware(dsp->conf, dsp);
  589. dsp_dtmf_hardware(dsp);
  590. dsp_rx_off(dsp);
  591. break;
  592. default:
  593. if (dsp_debug & DEBUG_DSP_CORE)
  594. printk(KERN_DEBUG "%s: ctrl req %x unhandled\n",
  595. __func__, cont);
  596. ret = -EINVAL;
  597. }
  598. return ret;
  599. }
  600. static void
  601. get_features(struct mISDNchannel *ch)
  602. {
  603. struct dsp *dsp = container_of(ch, struct dsp, ch);
  604. struct mISDN_ctrl_req cq;
  605. if (!ch->peer) {
  606. if (dsp_debug & DEBUG_DSP_CORE)
  607. printk(KERN_DEBUG "%s: no peer, no features\n",
  608. __func__);
  609. return;
  610. }
  611. memset(&cq, 0, sizeof(cq));
  612. cq.op = MISDN_CTRL_GETOP;
  613. if (ch->peer->ctrl(ch->peer, CONTROL_CHANNEL, &cq) < 0) {
  614. printk(KERN_DEBUG "%s: CONTROL_CHANNEL failed\n",
  615. __func__);
  616. return;
  617. }
  618. if (cq.op & MISDN_CTRL_RX_OFF)
  619. dsp->features_rx_off = 1;
  620. if (cq.op & MISDN_CTRL_FILL_EMPTY)
  621. dsp->features_fill_empty = 1;
  622. if (dsp_options & DSP_OPT_NOHARDWARE)
  623. return;
  624. if ((cq.op & MISDN_CTRL_HW_FEATURES_OP)) {
  625. cq.op = MISDN_CTRL_HW_FEATURES;
  626. *((u_long *)&cq.p1) = (u_long)&dsp->features;
  627. if (ch->peer->ctrl(ch->peer, CONTROL_CHANNEL, &cq)) {
  628. printk(KERN_DEBUG "%s: 2nd CONTROL_CHANNEL failed\n",
  629. __func__);
  630. }
  631. } else
  632. if (dsp_debug & DEBUG_DSP_CORE)
  633. printk(KERN_DEBUG "%s: features not supported for %s\n",
  634. __func__, dsp->name);
  635. }
  636. static int
  637. dsp_function(struct mISDNchannel *ch, struct sk_buff *skb)
  638. {
  639. struct dsp *dsp = container_of(ch, struct dsp, ch);
  640. struct mISDNhead *hh;
  641. int ret = 0;
  642. u8 *digits = NULL;
  643. u_long flags;
  644. hh = mISDN_HEAD_P(skb);
  645. switch (hh->prim) {
  646. /* FROM DOWN */
  647. case (PH_DATA_CNF):
  648. dsp->data_pending = 0;
  649. /* trigger next hdlc frame, if any */
  650. if (dsp->hdlc) {
  651. spin_lock_irqsave(&dsp_lock, flags);
  652. if (dsp->b_active)
  653. schedule_work(&dsp->workq);
  654. spin_unlock_irqrestore(&dsp_lock, flags);
  655. }
  656. break;
  657. case (PH_DATA_IND):
  658. case (DL_DATA_IND):
  659. if (skb->len < 1) {
  660. ret = -EINVAL;
  661. break;
  662. }
  663. if (dsp->rx_is_off) {
  664. if (dsp_debug & DEBUG_DSP_CORE)
  665. printk(KERN_DEBUG "%s: rx-data during rx_off"
  666. " for %s\n",
  667. __func__, dsp->name);
  668. }
  669. if (dsp->hdlc) {
  670. /* hdlc */
  671. spin_lock_irqsave(&dsp_lock, flags);
  672. dsp_cmx_hdlc(dsp, skb);
  673. spin_unlock_irqrestore(&dsp_lock, flags);
  674. if (dsp->rx_disabled) {
  675. /* if receive is not allowed */
  676. break;
  677. }
  678. hh->prim = DL_DATA_IND;
  679. if (dsp->up)
  680. return dsp->up->send(dsp->up, skb);
  681. break;
  682. }
  683. spin_lock_irqsave(&dsp_lock, flags);
  684. /* decrypt if enabled */
  685. if (dsp->bf_enable)
  686. dsp_bf_decrypt(dsp, skb->data, skb->len);
  687. /* pipeline */
  688. if (dsp->pipeline.inuse)
  689. dsp_pipeline_process_rx(&dsp->pipeline, skb->data,
  690. skb->len, hh->id);
  691. /* change volume if requested */
  692. if (dsp->rx_volume)
  693. dsp_change_volume(skb, dsp->rx_volume);
  694. /* check if dtmf soft decoding is turned on */
  695. if (dsp->dtmf.software) {
  696. digits = dsp_dtmf_goertzel_decode(dsp, skb->data,
  697. skb->len, (dsp_options&DSP_OPT_ULAW) ? 1 : 0);
  698. }
  699. /* we need to process receive data if software */
  700. if (dsp->conf && dsp->conf->software) {
  701. /* process data from card at cmx */
  702. dsp_cmx_receive(dsp, skb);
  703. }
  704. spin_unlock_irqrestore(&dsp_lock, flags);
  705. /* send dtmf result, if any */
  706. if (digits) {
  707. while (*digits) {
  708. int k;
  709. struct sk_buff *nskb;
  710. if (dsp_debug & DEBUG_DSP_DTMF)
  711. printk(KERN_DEBUG "%s: digit"
  712. "(%c) to layer %s\n",
  713. __func__, *digits, dsp->name);
  714. k = *digits | DTMF_TONE_VAL;
  715. nskb = _alloc_mISDN_skb(PH_CONTROL_IND,
  716. MISDN_ID_ANY, sizeof(int), &k,
  717. GFP_ATOMIC);
  718. if (nskb) {
  719. if (dsp->up) {
  720. if (dsp->up->send(
  721. dsp->up, nskb))
  722. dev_kfree_skb(nskb);
  723. } else
  724. dev_kfree_skb(nskb);
  725. }
  726. digits++;
  727. }
  728. }
  729. if (dsp->rx_disabled) {
  730. /* if receive is not allowed */
  731. break;
  732. }
  733. hh->prim = DL_DATA_IND;
  734. if (dsp->up)
  735. return dsp->up->send(dsp->up, skb);
  736. break;
  737. case (PH_CONTROL_IND):
  738. if (dsp_debug & DEBUG_DSP_DTMFCOEFF)
  739. printk(KERN_DEBUG "%s: PH_CONTROL INDICATION "
  740. "received: %x (len %d) %s\n", __func__,
  741. hh->id, skb->len, dsp->name);
  742. switch (hh->id) {
  743. case (DTMF_HFC_COEF): /* getting coefficients */
  744. if (!dsp->dtmf.hardware) {
  745. if (dsp_debug & DEBUG_DSP_DTMFCOEFF)
  746. printk(KERN_DEBUG "%s: ignoring DTMF "
  747. "coefficients from HFC\n",
  748. __func__);
  749. break;
  750. }
  751. digits = dsp_dtmf_goertzel_decode(dsp, skb->data,
  752. skb->len, 2);
  753. while (*digits) {
  754. int k;
  755. struct sk_buff *nskb;
  756. if (dsp_debug & DEBUG_DSP_DTMF)
  757. printk(KERN_DEBUG "%s: digit"
  758. "(%c) to layer %s\n",
  759. __func__, *digits, dsp->name);
  760. k = *digits | DTMF_TONE_VAL;
  761. nskb = _alloc_mISDN_skb(PH_CONTROL_IND,
  762. MISDN_ID_ANY, sizeof(int), &k,
  763. GFP_ATOMIC);
  764. if (nskb) {
  765. if (dsp->up) {
  766. if (dsp->up->send(
  767. dsp->up, nskb))
  768. dev_kfree_skb(nskb);
  769. } else
  770. dev_kfree_skb(nskb);
  771. }
  772. digits++;
  773. }
  774. break;
  775. case (HFC_VOL_CHANGE_TX): /* change volume */
  776. if (skb->len != sizeof(int)) {
  777. ret = -EINVAL;
  778. break;
  779. }
  780. spin_lock_irqsave(&dsp_lock, flags);
  781. dsp->tx_volume = *((int *)skb->data);
  782. if (dsp_debug & DEBUG_DSP_CORE)
  783. printk(KERN_DEBUG "%s: change tx volume to "
  784. "%d\n", __func__, dsp->tx_volume);
  785. dsp_cmx_hardware(dsp->conf, dsp);
  786. dsp_dtmf_hardware(dsp);
  787. dsp_rx_off(dsp);
  788. spin_unlock_irqrestore(&dsp_lock, flags);
  789. break;
  790. default:
  791. if (dsp_debug & DEBUG_DSP_CORE)
  792. printk(KERN_DEBUG "%s: ctrl ind %x unhandled "
  793. "%s\n", __func__, hh->id, dsp->name);
  794. ret = -EINVAL;
  795. }
  796. break;
  797. case (PH_ACTIVATE_IND):
  798. case (PH_ACTIVATE_CNF):
  799. if (dsp_debug & DEBUG_DSP_CORE)
  800. printk(KERN_DEBUG "%s: b_channel is now active %s\n",
  801. __func__, dsp->name);
  802. /* bchannel now active */
  803. spin_lock_irqsave(&dsp_lock, flags);
  804. dsp->b_active = 1;
  805. dsp->data_pending = 0;
  806. dsp->rx_init = 1;
  807. /* rx_W and rx_R will be adjusted on first frame */
  808. dsp->rx_W = 0;
  809. dsp->rx_R = 0;
  810. memset(dsp->rx_buff, 0, sizeof(dsp->rx_buff));
  811. dsp_cmx_hardware(dsp->conf, dsp);
  812. dsp_dtmf_hardware(dsp);
  813. dsp_rx_off(dsp);
  814. spin_unlock_irqrestore(&dsp_lock, flags);
  815. if (dsp_debug & DEBUG_DSP_CORE)
  816. printk(KERN_DEBUG "%s: done with activation, sending "
  817. "confirm to user space. %s\n", __func__,
  818. dsp->name);
  819. /* send activation to upper layer */
  820. hh->prim = DL_ESTABLISH_CNF;
  821. if (dsp->up)
  822. return dsp->up->send(dsp->up, skb);
  823. break;
  824. case (PH_DEACTIVATE_IND):
  825. case (PH_DEACTIVATE_CNF):
  826. if (dsp_debug & DEBUG_DSP_CORE)
  827. printk(KERN_DEBUG "%s: b_channel is now inactive %s\n",
  828. __func__, dsp->name);
  829. /* bchannel now inactive */
  830. spin_lock_irqsave(&dsp_lock, flags);
  831. dsp->b_active = 0;
  832. dsp->data_pending = 0;
  833. dsp_cmx_hardware(dsp->conf, dsp);
  834. dsp_rx_off(dsp);
  835. spin_unlock_irqrestore(&dsp_lock, flags);
  836. hh->prim = DL_RELEASE_CNF;
  837. if (dsp->up)
  838. return dsp->up->send(dsp->up, skb);
  839. break;
  840. /* FROM UP */
  841. case (DL_DATA_REQ):
  842. case (PH_DATA_REQ):
  843. if (skb->len < 1) {
  844. ret = -EINVAL;
  845. break;
  846. }
  847. if (dsp->hdlc) {
  848. /* hdlc */
  849. if (!dsp->b_active) {
  850. ret = -EIO;
  851. break;
  852. }
  853. hh->prim = PH_DATA_REQ;
  854. spin_lock_irqsave(&dsp_lock, flags);
  855. skb_queue_tail(&dsp->sendq, skb);
  856. schedule_work(&dsp->workq);
  857. spin_unlock_irqrestore(&dsp_lock, flags);
  858. return 0;
  859. }
  860. /* send data to tx-buffer (if no tone is played) */
  861. if (!dsp->tone.tone) {
  862. spin_lock_irqsave(&dsp_lock, flags);
  863. dsp_cmx_transmit(dsp, skb);
  864. spin_unlock_irqrestore(&dsp_lock, flags);
  865. }
  866. break;
  867. case (PH_CONTROL_REQ):
  868. spin_lock_irqsave(&dsp_lock, flags);
  869. ret = dsp_control_req(dsp, hh, skb);
  870. spin_unlock_irqrestore(&dsp_lock, flags);
  871. break;
  872. case (DL_ESTABLISH_REQ):
  873. case (PH_ACTIVATE_REQ):
  874. if (dsp_debug & DEBUG_DSP_CORE)
  875. printk(KERN_DEBUG "%s: activating b_channel %s\n",
  876. __func__, dsp->name);
  877. if (dsp->dtmf.hardware || dsp->dtmf.software)
  878. dsp_dtmf_goertzel_init(dsp);
  879. get_features(ch);
  880. /* enable fill_empty feature */
  881. if (dsp->features_fill_empty)
  882. dsp_fill_empty(dsp);
  883. /* send ph_activate */
  884. hh->prim = PH_ACTIVATE_REQ;
  885. if (ch->peer)
  886. return ch->recv(ch->peer, skb);
  887. break;
  888. case (DL_RELEASE_REQ):
  889. case (PH_DEACTIVATE_REQ):
  890. if (dsp_debug & DEBUG_DSP_CORE)
  891. printk(KERN_DEBUG "%s: releasing b_channel %s\n",
  892. __func__, dsp->name);
  893. spin_lock_irqsave(&dsp_lock, flags);
  894. dsp->tone.tone = 0;
  895. dsp->tone.hardware = 0;
  896. dsp->tone.software = 0;
  897. if (timer_pending(&dsp->tone.tl))
  898. del_timer(&dsp->tone.tl);
  899. if (dsp->conf)
  900. dsp_cmx_conf(dsp, 0); /* dsp_cmx_hardware will also be
  901. called here */
  902. skb_queue_purge(&dsp->sendq);
  903. spin_unlock_irqrestore(&dsp_lock, flags);
  904. hh->prim = PH_DEACTIVATE_REQ;
  905. if (ch->peer)
  906. return ch->recv(ch->peer, skb);
  907. break;
  908. default:
  909. if (dsp_debug & DEBUG_DSP_CORE)
  910. printk(KERN_DEBUG "%s: msg %x unhandled %s\n",
  911. __func__, hh->prim, dsp->name);
  912. ret = -EINVAL;
  913. }
  914. if (!ret)
  915. dev_kfree_skb(skb);
  916. return ret;
  917. }
  918. static int
  919. dsp_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
  920. {
  921. struct dsp *dsp = container_of(ch, struct dsp, ch);
  922. u_long flags;
  923. int err = 0;
  924. if (debug & DEBUG_DSP_CTRL)
  925. printk(KERN_DEBUG "%s:(%x)\n", __func__, cmd);
  926. switch (cmd) {
  927. case OPEN_CHANNEL:
  928. break;
  929. case CLOSE_CHANNEL:
  930. if (dsp->ch.peer)
  931. dsp->ch.peer->ctrl(dsp->ch.peer, CLOSE_CHANNEL, NULL);
  932. /* wait until workqueue has finished,
  933. * must lock here, or we may hit send-process currently
  934. * queueing. */
  935. spin_lock_irqsave(&dsp_lock, flags);
  936. dsp->b_active = 0;
  937. spin_unlock_irqrestore(&dsp_lock, flags);
  938. /* MUST not be locked, because it waits until queue is done. */
  939. cancel_work_sync(&dsp->workq);
  940. spin_lock_irqsave(&dsp_lock, flags);
  941. if (timer_pending(&dsp->tone.tl))
  942. del_timer(&dsp->tone.tl);
  943. skb_queue_purge(&dsp->sendq);
  944. if (dsp_debug & DEBUG_DSP_CTRL)
  945. printk(KERN_DEBUG "%s: releasing member %s\n",
  946. __func__, dsp->name);
  947. dsp->b_active = 0;
  948. dsp_cmx_conf(dsp, 0); /* dsp_cmx_hardware will also be called
  949. here */
  950. dsp_pipeline_destroy(&dsp->pipeline);
  951. if (dsp_debug & DEBUG_DSP_CTRL)
  952. printk(KERN_DEBUG "%s: remove & destroy object %s\n",
  953. __func__, dsp->name);
  954. list_del(&dsp->list);
  955. spin_unlock_irqrestore(&dsp_lock, flags);
  956. if (dsp_debug & DEBUG_DSP_CTRL)
  957. printk(KERN_DEBUG "%s: dsp instance released\n",
  958. __func__);
  959. vfree(dsp);
  960. module_put(THIS_MODULE);
  961. break;
  962. }
  963. return err;
  964. }
  965. static void
  966. dsp_send_bh(struct work_struct *work)
  967. {
  968. struct dsp *dsp = container_of(work, struct dsp, workq);
  969. struct sk_buff *skb;
  970. struct mISDNhead *hh;
  971. if (dsp->hdlc && dsp->data_pending)
  972. return; /* wait until data has been acknowledged */
  973. /* send queued data */
  974. while ((skb = skb_dequeue(&dsp->sendq))) {
  975. /* in locked date, we must have still data in queue */
  976. if (dsp->data_pending) {
  977. if (dsp_debug & DEBUG_DSP_CORE)
  978. printk(KERN_DEBUG "%s: fifo full %s, this is "
  979. "no bug!\n", __func__, dsp->name);
  980. /* flush transparent data, if not acked */
  981. dev_kfree_skb(skb);
  982. continue;
  983. }
  984. hh = mISDN_HEAD_P(skb);
  985. if (hh->prim == DL_DATA_REQ) {
  986. /* send packet up */
  987. if (dsp->up) {
  988. if (dsp->up->send(dsp->up, skb))
  989. dev_kfree_skb(skb);
  990. } else
  991. dev_kfree_skb(skb);
  992. } else {
  993. /* send packet down */
  994. if (dsp->ch.peer) {
  995. dsp->data_pending = 1;
  996. if (dsp->ch.recv(dsp->ch.peer, skb)) {
  997. dev_kfree_skb(skb);
  998. dsp->data_pending = 0;
  999. }
  1000. } else
  1001. dev_kfree_skb(skb);
  1002. }
  1003. }
  1004. }
  1005. static int
  1006. dspcreate(struct channel_req *crq)
  1007. {
  1008. struct dsp *ndsp;
  1009. u_long flags;
  1010. if (crq->protocol != ISDN_P_B_L2DSP
  1011. && crq->protocol != ISDN_P_B_L2DSPHDLC)
  1012. return -EPROTONOSUPPORT;
  1013. ndsp = vmalloc(sizeof(struct dsp));
  1014. if (!ndsp) {
  1015. printk(KERN_ERR "%s: vmalloc struct dsp failed\n", __func__);
  1016. return -ENOMEM;
  1017. }
  1018. memset(ndsp, 0, sizeof(struct dsp));
  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 dsp_init(void)
  1069. {
  1070. int err;
  1071. int tics;
  1072. printk(KERN_INFO "DSP modul %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 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);