1*960366cfSKarsten Keil /* 2*960366cfSKarsten Keil * Audio support data for ISDN4Linux. 3*960366cfSKarsten Keil * 4*960366cfSKarsten Keil * Copyright 2002/2003 by Andreas Eversberg (jolly@eversberg.eu) 5*960366cfSKarsten Keil * 6*960366cfSKarsten Keil * This software may be used and distributed according to the terms 7*960366cfSKarsten Keil * of the GNU General Public License, incorporated herein by reference. 8*960366cfSKarsten Keil * 9*960366cfSKarsten Keil */ 10*960366cfSKarsten Keil 11*960366cfSKarsten Keil #define DEBUG_DSP_CTRL 0x0001 12*960366cfSKarsten Keil #define DEBUG_DSP_CORE 0x0002 13*960366cfSKarsten Keil #define DEBUG_DSP_DTMF 0x0004 14*960366cfSKarsten Keil #define DEBUG_DSP_CMX 0x0010 15*960366cfSKarsten Keil #define DEBUG_DSP_TONE 0x0020 16*960366cfSKarsten Keil #define DEBUG_DSP_BLOWFISH 0x0040 17*960366cfSKarsten Keil #define DEBUG_DSP_DELAY 0x0100 18*960366cfSKarsten Keil #define DEBUG_DSP_DTMFCOEFF 0x8000 /* heavy output */ 19*960366cfSKarsten Keil 20*960366cfSKarsten Keil /* options may be: 21*960366cfSKarsten Keil * 22*960366cfSKarsten Keil * bit 0 = use ulaw instead of alaw 23*960366cfSKarsten Keil * bit 1 = enable hfc hardware accelleration for all channels 24*960366cfSKarsten Keil * 25*960366cfSKarsten Keil */ 26*960366cfSKarsten Keil #define DSP_OPT_ULAW (1<<0) 27*960366cfSKarsten Keil #define DSP_OPT_NOHARDWARE (1<<1) 28*960366cfSKarsten Keil 29*960366cfSKarsten Keil #include <linux/timer.h> 30*960366cfSKarsten Keil #include <linux/workqueue.h> 31*960366cfSKarsten Keil 32*960366cfSKarsten Keil #include "dsp_ecdis.h" 33*960366cfSKarsten Keil 34*960366cfSKarsten Keil extern int dsp_options; 35*960366cfSKarsten Keil extern int dsp_debug; 36*960366cfSKarsten Keil extern int dsp_poll; 37*960366cfSKarsten Keil extern int dsp_tics; 38*960366cfSKarsten Keil extern spinlock_t dsp_lock; 39*960366cfSKarsten Keil extern struct work_struct dsp_workq; 40*960366cfSKarsten Keil extern u32 dsp_poll_diff; /* calculated fix-comma corrected poll value */ 41*960366cfSKarsten Keil 42*960366cfSKarsten Keil /*************** 43*960366cfSKarsten Keil * audio stuff * 44*960366cfSKarsten Keil ***************/ 45*960366cfSKarsten Keil 46*960366cfSKarsten Keil extern s32 dsp_audio_alaw_to_s32[256]; 47*960366cfSKarsten Keil extern s32 dsp_audio_ulaw_to_s32[256]; 48*960366cfSKarsten Keil extern s32 *dsp_audio_law_to_s32; 49*960366cfSKarsten Keil extern u8 dsp_audio_s16_to_law[65536]; 50*960366cfSKarsten Keil extern u8 dsp_audio_alaw_to_ulaw[256]; 51*960366cfSKarsten Keil extern u8 dsp_audio_mix_law[65536]; 52*960366cfSKarsten Keil extern u8 dsp_audio_seven2law[128]; 53*960366cfSKarsten Keil extern u8 dsp_audio_law2seven[256]; 54*960366cfSKarsten Keil extern void dsp_audio_generate_law_tables(void); 55*960366cfSKarsten Keil extern void dsp_audio_generate_s2law_table(void); 56*960366cfSKarsten Keil extern void dsp_audio_generate_seven(void); 57*960366cfSKarsten Keil extern void dsp_audio_generate_mix_table(void); 58*960366cfSKarsten Keil extern void dsp_audio_generate_ulaw_samples(void); 59*960366cfSKarsten Keil extern void dsp_audio_generate_volume_changes(void); 60*960366cfSKarsten Keil extern u8 dsp_silence; 61*960366cfSKarsten Keil 62*960366cfSKarsten Keil 63*960366cfSKarsten Keil /************* 64*960366cfSKarsten Keil * cmx stuff * 65*960366cfSKarsten Keil *************/ 66*960366cfSKarsten Keil 67*960366cfSKarsten Keil #define MAX_POLL 256 /* maximum number of send-chunks */ 68*960366cfSKarsten Keil 69*960366cfSKarsten Keil #define CMX_BUFF_SIZE 0x8000 /* must be 2**n (0x1000 about 1/2 second) */ 70*960366cfSKarsten Keil #define CMX_BUFF_HALF 0x4000 /* CMX_BUFF_SIZE / 2 */ 71*960366cfSKarsten Keil #define CMX_BUFF_MASK 0x7fff /* CMX_BUFF_SIZE - 1 */ 72*960366cfSKarsten Keil 73*960366cfSKarsten Keil /* how many seconds will we check the lowest delay until the jitter buffer 74*960366cfSKarsten Keil is reduced by that delay */ 75*960366cfSKarsten Keil #define MAX_SECONDS_JITTER_CHECK 5 76*960366cfSKarsten Keil 77*960366cfSKarsten Keil extern struct timer_list dsp_spl_tl; 78*960366cfSKarsten Keil extern u32 dsp_spl_jiffies; 79*960366cfSKarsten Keil 80*960366cfSKarsten Keil /* the structure of conferences: 81*960366cfSKarsten Keil * 82*960366cfSKarsten Keil * each conference has a unique number, given by user space. 83*960366cfSKarsten Keil * the conferences are linked in a chain. 84*960366cfSKarsten Keil * each conference has members linked in a chain. 85*960366cfSKarsten Keil * each dsplayer points to a member, each member points to a dsplayer. 86*960366cfSKarsten Keil */ 87*960366cfSKarsten Keil 88*960366cfSKarsten Keil /* all members within a conference (this is linked 1:1 with the dsp) */ 89*960366cfSKarsten Keil struct dsp; 90*960366cfSKarsten Keil struct dsp_conf_member { 91*960366cfSKarsten Keil struct list_head list; 92*960366cfSKarsten Keil struct dsp *dsp; 93*960366cfSKarsten Keil }; 94*960366cfSKarsten Keil 95*960366cfSKarsten Keil /* the list of all conferences */ 96*960366cfSKarsten Keil struct dsp_conf { 97*960366cfSKarsten Keil struct list_head list; 98*960366cfSKarsten Keil u32 id; 99*960366cfSKarsten Keil /* all cmx stacks with the same ID are 100*960366cfSKarsten Keil connected */ 101*960366cfSKarsten Keil struct list_head mlist; 102*960366cfSKarsten Keil int software; /* conf is processed by software */ 103*960366cfSKarsten Keil int hardware; /* conf is processed by hardware */ 104*960366cfSKarsten Keil /* note: if both unset, has only one member */ 105*960366cfSKarsten Keil }; 106*960366cfSKarsten Keil 107*960366cfSKarsten Keil 108*960366cfSKarsten Keil /************** 109*960366cfSKarsten Keil * DTMF stuff * 110*960366cfSKarsten Keil **************/ 111*960366cfSKarsten Keil 112*960366cfSKarsten Keil #define DSP_DTMF_NPOINTS 102 113*960366cfSKarsten Keil 114*960366cfSKarsten Keil #define ECHOCAN_BUFLEN (4*128) 115*960366cfSKarsten Keil 116*960366cfSKarsten Keil struct dsp_dtmf { 117*960366cfSKarsten Keil int treshold; /* above this is dtmf (square of) */ 118*960366cfSKarsten Keil int software; /* dtmf uses software decoding */ 119*960366cfSKarsten Keil int hardware; /* dtmf uses hardware decoding */ 120*960366cfSKarsten Keil int size; /* number of bytes in buffer */ 121*960366cfSKarsten Keil signed short buffer[DSP_DTMF_NPOINTS]; 122*960366cfSKarsten Keil /* buffers one full dtmf frame */ 123*960366cfSKarsten Keil u8 lastwhat, lastdigit; 124*960366cfSKarsten Keil int count; 125*960366cfSKarsten Keil u8 digits[16]; /* just the dtmf result */ 126*960366cfSKarsten Keil }; 127*960366cfSKarsten Keil 128*960366cfSKarsten Keil 129*960366cfSKarsten Keil /****************** 130*960366cfSKarsten Keil * pipeline stuff * 131*960366cfSKarsten Keil ******************/ 132*960366cfSKarsten Keil struct dsp_pipeline { 133*960366cfSKarsten Keil rwlock_t lock; 134*960366cfSKarsten Keil struct list_head list; 135*960366cfSKarsten Keil int inuse; 136*960366cfSKarsten Keil }; 137*960366cfSKarsten Keil 138*960366cfSKarsten Keil /*************** 139*960366cfSKarsten Keil * tones stuff * 140*960366cfSKarsten Keil ***************/ 141*960366cfSKarsten Keil 142*960366cfSKarsten Keil struct dsp_tone { 143*960366cfSKarsten Keil int software; /* tones are generated by software */ 144*960366cfSKarsten Keil int hardware; /* tones are generated by hardware */ 145*960366cfSKarsten Keil int tone; 146*960366cfSKarsten Keil void *pattern; 147*960366cfSKarsten Keil int count; 148*960366cfSKarsten Keil int index; 149*960366cfSKarsten Keil struct timer_list tl; 150*960366cfSKarsten Keil }; 151*960366cfSKarsten Keil 152*960366cfSKarsten Keil /***************** 153*960366cfSKarsten Keil * general stuff * 154*960366cfSKarsten Keil *****************/ 155*960366cfSKarsten Keil 156*960366cfSKarsten Keil struct dsp { 157*960366cfSKarsten Keil struct list_head list; 158*960366cfSKarsten Keil struct mISDNchannel ch; 159*960366cfSKarsten Keil struct mISDNchannel *up; 160*960366cfSKarsten Keil unsigned char name[64]; 161*960366cfSKarsten Keil int b_active; 162*960366cfSKarsten Keil int echo; /* echo is enabled */ 163*960366cfSKarsten Keil int rx_disabled; /* what the user wants */ 164*960366cfSKarsten Keil int rx_is_off; /* what the card is */ 165*960366cfSKarsten Keil int tx_mix; 166*960366cfSKarsten Keil struct dsp_tone tone; 167*960366cfSKarsten Keil struct dsp_dtmf dtmf; 168*960366cfSKarsten Keil int tx_volume, rx_volume; 169*960366cfSKarsten Keil 170*960366cfSKarsten Keil /* queue for sending frames */ 171*960366cfSKarsten Keil struct work_struct workq; 172*960366cfSKarsten Keil struct sk_buff_head sendq; 173*960366cfSKarsten Keil int hdlc; /* if mode is hdlc */ 174*960366cfSKarsten Keil int data_pending; /* currently an unconfirmed frame */ 175*960366cfSKarsten Keil 176*960366cfSKarsten Keil /* conference stuff */ 177*960366cfSKarsten Keil u32 conf_id; 178*960366cfSKarsten Keil struct dsp_conf *conf; 179*960366cfSKarsten Keil struct dsp_conf_member 180*960366cfSKarsten Keil *member; 181*960366cfSKarsten Keil 182*960366cfSKarsten Keil /* buffer stuff */ 183*960366cfSKarsten Keil int rx_W; /* current write pos for data without timestamp */ 184*960366cfSKarsten Keil int rx_R; /* current read pos for transmit clock */ 185*960366cfSKarsten Keil int rx_init; /* if set, pointers will be adjusted first */ 186*960366cfSKarsten Keil int tx_W; /* current write pos for transmit data */ 187*960366cfSKarsten Keil int tx_R; /* current read pos for transmit clock */ 188*960366cfSKarsten Keil int rx_delay[MAX_SECONDS_JITTER_CHECK]; 189*960366cfSKarsten Keil int tx_delay[MAX_SECONDS_JITTER_CHECK]; 190*960366cfSKarsten Keil u8 tx_buff[CMX_BUFF_SIZE]; 191*960366cfSKarsten Keil u8 rx_buff[CMX_BUFF_SIZE]; 192*960366cfSKarsten Keil int last_tx; /* if set, we transmitted last poll interval */ 193*960366cfSKarsten Keil int cmx_delay; /* initial delay of buffers, 194*960366cfSKarsten Keil or 0 for dynamic jitter buffer */ 195*960366cfSKarsten Keil int tx_dejitter; /* if set, dejitter tx buffer */ 196*960366cfSKarsten Keil int tx_data; /* enables tx-data of CMX to upper layer */ 197*960366cfSKarsten Keil 198*960366cfSKarsten Keil /* hardware stuff */ 199*960366cfSKarsten Keil struct dsp_features features; 200*960366cfSKarsten Keil int features_rx_off; /* set if rx_off is featured */ 201*960366cfSKarsten Keil int pcm_slot_rx; /* current PCM slot (or -1) */ 202*960366cfSKarsten Keil int pcm_bank_rx; 203*960366cfSKarsten Keil int pcm_slot_tx; 204*960366cfSKarsten Keil int pcm_bank_tx; 205*960366cfSKarsten Keil int hfc_conf; /* unique id of current conference (or -1) */ 206*960366cfSKarsten Keil 207*960366cfSKarsten Keil /* encryption stuff */ 208*960366cfSKarsten Keil int bf_enable; 209*960366cfSKarsten Keil u32 bf_p[18]; 210*960366cfSKarsten Keil u32 bf_s[1024]; 211*960366cfSKarsten Keil int bf_crypt_pos; 212*960366cfSKarsten Keil u8 bf_data_in[9]; 213*960366cfSKarsten Keil u8 bf_crypt_out[9]; 214*960366cfSKarsten Keil int bf_decrypt_in_pos; 215*960366cfSKarsten Keil int bf_decrypt_out_pos; 216*960366cfSKarsten Keil u8 bf_crypt_inring[16]; 217*960366cfSKarsten Keil u8 bf_data_out[9]; 218*960366cfSKarsten Keil int bf_sync; 219*960366cfSKarsten Keil 220*960366cfSKarsten Keil struct dsp_pipeline 221*960366cfSKarsten Keil pipeline; 222*960366cfSKarsten Keil }; 223*960366cfSKarsten Keil 224*960366cfSKarsten Keil /* functions */ 225*960366cfSKarsten Keil 226*960366cfSKarsten Keil extern void dsp_change_volume(struct sk_buff *skb, int volume); 227*960366cfSKarsten Keil 228*960366cfSKarsten Keil extern struct list_head dsp_ilist; 229*960366cfSKarsten Keil extern struct list_head conf_ilist; 230*960366cfSKarsten Keil extern void dsp_cmx_debug(struct dsp *dsp); 231*960366cfSKarsten Keil extern void dsp_cmx_hardware(struct dsp_conf *conf, struct dsp *dsp); 232*960366cfSKarsten Keil extern int dsp_cmx_conf(struct dsp *dsp, u32 conf_id); 233*960366cfSKarsten Keil extern void dsp_cmx_receive(struct dsp *dsp, struct sk_buff *skb); 234*960366cfSKarsten Keil extern void dsp_cmx_hdlc(struct dsp *dsp, struct sk_buff *skb); 235*960366cfSKarsten Keil extern void dsp_cmx_send(void *arg); 236*960366cfSKarsten Keil extern void dsp_cmx_transmit(struct dsp *dsp, struct sk_buff *skb); 237*960366cfSKarsten Keil extern int dsp_cmx_del_conf_member(struct dsp *dsp); 238*960366cfSKarsten Keil extern int dsp_cmx_del_conf(struct dsp_conf *conf); 239*960366cfSKarsten Keil 240*960366cfSKarsten Keil extern void dsp_dtmf_goertzel_init(struct dsp *dsp); 241*960366cfSKarsten Keil extern void dsp_dtmf_hardware(struct dsp *dsp); 242*960366cfSKarsten Keil extern u8 *dsp_dtmf_goertzel_decode(struct dsp *dsp, u8 *data, int len, 243*960366cfSKarsten Keil int fmt); 244*960366cfSKarsten Keil 245*960366cfSKarsten Keil extern int dsp_tone(struct dsp *dsp, int tone); 246*960366cfSKarsten Keil extern void dsp_tone_copy(struct dsp *dsp, u8 *data, int len); 247*960366cfSKarsten Keil extern void dsp_tone_timeout(void *arg); 248*960366cfSKarsten Keil 249*960366cfSKarsten Keil extern void dsp_bf_encrypt(struct dsp *dsp, u8 *data, int len); 250*960366cfSKarsten Keil extern void dsp_bf_decrypt(struct dsp *dsp, u8 *data, int len); 251*960366cfSKarsten Keil extern int dsp_bf_init(struct dsp *dsp, const u8 *key, unsigned int keylen); 252*960366cfSKarsten Keil extern void dsp_bf_cleanup(struct dsp *dsp); 253*960366cfSKarsten Keil 254*960366cfSKarsten Keil extern int dsp_pipeline_module_init(void); 255*960366cfSKarsten Keil extern void dsp_pipeline_module_exit(void); 256*960366cfSKarsten Keil extern int dsp_pipeline_init(struct dsp_pipeline *pipeline); 257*960366cfSKarsten Keil extern void dsp_pipeline_destroy(struct dsp_pipeline *pipeline); 258*960366cfSKarsten Keil extern int dsp_pipeline_build(struct dsp_pipeline *pipeline, const char *cfg); 259*960366cfSKarsten Keil extern void dsp_pipeline_process_tx(struct dsp_pipeline *pipeline, u8 *data, 260*960366cfSKarsten Keil int len); 261*960366cfSKarsten Keil extern void dsp_pipeline_process_rx(struct dsp_pipeline *pipeline, u8 *data, 262*960366cfSKarsten Keil int len); 263*960366cfSKarsten Keil 264