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