dsp_core.c 33 KB

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