1960366cfSKarsten Keil /* 2960366cfSKarsten Keil * Audio support data for ISDN4Linux. 3960366cfSKarsten Keil * 4960366cfSKarsten Keil * Copyright 2002/2003 by Andreas Eversberg (jolly@eversberg.eu) 5960366cfSKarsten Keil * 6960366cfSKarsten Keil * This software may be used and distributed according to the terms 7960366cfSKarsten Keil * of the GNU General Public License, incorporated herein by reference. 8960366cfSKarsten Keil * 9960366cfSKarsten Keil */ 10960366cfSKarsten Keil 11960366cfSKarsten Keil #define DEBUG_DSP_CTRL 0x0001 12960366cfSKarsten Keil #define DEBUG_DSP_CORE 0x0002 13960366cfSKarsten Keil #define DEBUG_DSP_DTMF 0x0004 14960366cfSKarsten Keil #define DEBUG_DSP_CMX 0x0010 15960366cfSKarsten Keil #define DEBUG_DSP_TONE 0x0020 16960366cfSKarsten Keil #define DEBUG_DSP_BLOWFISH 0x0040 17960366cfSKarsten Keil #define DEBUG_DSP_DELAY 0x0100 18190f71d9SAndreas Eversberg #define DEBUG_DSP_CLOCK 0x0200 19960366cfSKarsten Keil #define DEBUG_DSP_DTMFCOEFF 0x8000 /* heavy output */ 20960366cfSKarsten Keil 21960366cfSKarsten Keil /* options may be: 22960366cfSKarsten Keil * 23960366cfSKarsten Keil * bit 0 = use ulaw instead of alaw 2425985edcSLucas De Marchi * bit 1 = enable hfc hardware acceleration for all channels 25960366cfSKarsten Keil * 26960366cfSKarsten Keil */ 27960366cfSKarsten Keil #define DSP_OPT_ULAW (1 << 0) 28960366cfSKarsten Keil #define DSP_OPT_NOHARDWARE (1 << 1) 29960366cfSKarsten Keil 30960366cfSKarsten Keil #include <linux/timer.h> 31960366cfSKarsten Keil #include <linux/workqueue.h> 32960366cfSKarsten Keil 33960366cfSKarsten Keil #include "dsp_ecdis.h" 34960366cfSKarsten Keil 35960366cfSKarsten Keil extern int dsp_options; 36960366cfSKarsten Keil extern int dsp_debug; 37960366cfSKarsten Keil extern int dsp_poll; 38960366cfSKarsten Keil extern int dsp_tics; 39960366cfSKarsten Keil extern spinlock_t dsp_lock; 40960366cfSKarsten Keil extern struct work_struct dsp_workq; 41960366cfSKarsten Keil extern u32 dsp_poll_diff; /* calculated fix-comma corrected poll value */ 42960366cfSKarsten Keil 43960366cfSKarsten Keil /*************** 44960366cfSKarsten Keil * audio stuff * 45960366cfSKarsten Keil ***************/ 46960366cfSKarsten Keil 47960366cfSKarsten Keil extern s32 dsp_audio_alaw_to_s32[256]; 48960366cfSKarsten Keil extern s32 dsp_audio_ulaw_to_s32[256]; 49960366cfSKarsten Keil extern s32 *dsp_audio_law_to_s32; 50960366cfSKarsten Keil extern u8 dsp_audio_s16_to_law[65536]; 51960366cfSKarsten Keil extern u8 dsp_audio_alaw_to_ulaw[256]; 52960366cfSKarsten Keil extern u8 dsp_audio_mix_law[65536]; 53960366cfSKarsten Keil extern u8 dsp_audio_seven2law[128]; 54960366cfSKarsten Keil extern u8 dsp_audio_law2seven[256]; 55960366cfSKarsten Keil extern void dsp_audio_generate_law_tables(void); 56960366cfSKarsten Keil extern void dsp_audio_generate_s2law_table(void); 57960366cfSKarsten Keil extern void dsp_audio_generate_seven(void); 58960366cfSKarsten Keil extern void dsp_audio_generate_mix_table(void); 59960366cfSKarsten Keil extern void dsp_audio_generate_ulaw_samples(void); 60960366cfSKarsten Keil extern void dsp_audio_generate_volume_changes(void); 61960366cfSKarsten Keil extern u8 dsp_silence; 62960366cfSKarsten Keil 63960366cfSKarsten Keil 64960366cfSKarsten Keil /************* 65960366cfSKarsten Keil * cmx stuff * 66960366cfSKarsten Keil *************/ 67960366cfSKarsten Keil 68960366cfSKarsten Keil #define MAX_POLL 256 /* maximum number of send-chunks */ 69960366cfSKarsten Keil 70960366cfSKarsten Keil #define CMX_BUFF_SIZE 0x8000 /* must be 2**n (0x1000 about 1/2 second) */ 71960366cfSKarsten Keil #define CMX_BUFF_HALF 0x4000 /* CMX_BUFF_SIZE / 2 */ 72960366cfSKarsten Keil #define CMX_BUFF_MASK 0x7fff /* CMX_BUFF_SIZE - 1 */ 73960366cfSKarsten Keil 74960366cfSKarsten Keil /* how many seconds will we check the lowest delay until the jitter buffer 75960366cfSKarsten Keil is reduced by that delay */ 76960366cfSKarsten Keil #define MAX_SECONDS_JITTER_CHECK 5 77960366cfSKarsten Keil 78960366cfSKarsten Keil extern struct timer_list dsp_spl_tl; 799cf6ace5SKarsten Keil 809cf6ace5SKarsten Keil /* the datatype need to match jiffies datatype */ 819cf6ace5SKarsten Keil extern unsigned long dsp_spl_jiffies; 82960366cfSKarsten Keil 83960366cfSKarsten Keil /* the structure of conferences: 84960366cfSKarsten Keil * 85960366cfSKarsten Keil * each conference has a unique number, given by user space. 86960366cfSKarsten Keil * the conferences are linked in a chain. 87960366cfSKarsten Keil * each conference has members linked in a chain. 88960366cfSKarsten Keil * each dsplayer points to a member, each member points to a dsplayer. 89960366cfSKarsten Keil */ 90960366cfSKarsten Keil 91960366cfSKarsten Keil /* all members within a conference (this is linked 1:1 with the dsp) */ 92960366cfSKarsten Keil struct dsp; 93960366cfSKarsten Keil struct dsp_conf_member { 94960366cfSKarsten Keil struct list_head list; 95960366cfSKarsten Keil struct dsp *dsp; 96960366cfSKarsten Keil }; 97960366cfSKarsten Keil 98960366cfSKarsten Keil /* the list of all conferences */ 99960366cfSKarsten Keil struct dsp_conf { 100960366cfSKarsten Keil struct list_head list; 101960366cfSKarsten Keil u32 id; 102960366cfSKarsten Keil /* all cmx stacks with the same ID are 103960366cfSKarsten Keil connected */ 104960366cfSKarsten Keil struct list_head mlist; 105960366cfSKarsten Keil int software; /* conf is processed by software */ 106960366cfSKarsten Keil int hardware; /* conf is processed by hardware */ 107960366cfSKarsten Keil /* note: if both unset, has only one member */ 108960366cfSKarsten Keil }; 109960366cfSKarsten Keil 110960366cfSKarsten Keil 111960366cfSKarsten Keil /************** 112960366cfSKarsten Keil * DTMF stuff * 113960366cfSKarsten Keil **************/ 114960366cfSKarsten Keil 115960366cfSKarsten Keil #define DSP_DTMF_NPOINTS 102 116960366cfSKarsten Keil 117a5355c27SAndreas Eversberg #define ECHOCAN_BUFF_SIZE 0x400 /* must be 2**n */ 118a5355c27SAndreas Eversberg #define ECHOCAN_BUFF_MASK 0x3ff /* -1 */ 119960366cfSKarsten Keil 120960366cfSKarsten Keil struct dsp_dtmf { 121b0579d74SAndreas Eversberg int enable; /* dtmf is enabled */ 122960366cfSKarsten Keil int treshold; /* above this is dtmf (square of) */ 123960366cfSKarsten Keil int software; /* dtmf uses software decoding */ 124960366cfSKarsten Keil int hardware; /* dtmf uses hardware decoding */ 125960366cfSKarsten Keil int size; /* number of bytes in buffer */ 126960366cfSKarsten Keil signed short buffer[DSP_DTMF_NPOINTS]; 127960366cfSKarsten Keil /* buffers one full dtmf frame */ 128960366cfSKarsten Keil u8 lastwhat, lastdigit; 129960366cfSKarsten Keil int count; 130b5df5a5cSAndreas Eversberg u8 digits[16]; /* dtmf result */ 131960366cfSKarsten Keil }; 132960366cfSKarsten Keil 133960366cfSKarsten Keil 134960366cfSKarsten Keil /****************** 135960366cfSKarsten Keil * pipeline stuff * 136960366cfSKarsten Keil ******************/ 137960366cfSKarsten Keil struct dsp_pipeline { 138960366cfSKarsten Keil rwlock_t lock; 139960366cfSKarsten Keil struct list_head list; 140960366cfSKarsten Keil int inuse; 141960366cfSKarsten Keil }; 142960366cfSKarsten Keil 143960366cfSKarsten Keil /*************** 144960366cfSKarsten Keil * tones stuff * 145960366cfSKarsten Keil ***************/ 146960366cfSKarsten Keil 147960366cfSKarsten Keil struct dsp_tone { 148960366cfSKarsten Keil int software; /* tones are generated by software */ 149960366cfSKarsten Keil int hardware; /* tones are generated by hardware */ 150960366cfSKarsten Keil int tone; 151960366cfSKarsten Keil void *pattern; 152960366cfSKarsten Keil int count; 153960366cfSKarsten Keil int index; 154960366cfSKarsten Keil struct timer_list tl; 155960366cfSKarsten Keil }; 156960366cfSKarsten Keil 157bc138ec4SAndreas Eversberg /*************** 158bc138ec4SAndreas Eversberg * echo stuff * 159bc138ec4SAndreas Eversberg ***************/ 160bc138ec4SAndreas Eversberg 161bc138ec4SAndreas Eversberg struct dsp_echo { 162bc138ec4SAndreas Eversberg int software; /* echo is generated by software */ 163bc138ec4SAndreas Eversberg int hardware; /* echo is generated by hardware */ 164bc138ec4SAndreas Eversberg }; 165bc138ec4SAndreas Eversberg 166960366cfSKarsten Keil /***************** 167960366cfSKarsten Keil * general stuff * 168960366cfSKarsten Keil *****************/ 169960366cfSKarsten Keil 170960366cfSKarsten Keil struct dsp { 171960366cfSKarsten Keil struct list_head list; 172960366cfSKarsten Keil struct mISDNchannel ch; 173960366cfSKarsten Keil struct mISDNchannel *up; 174960366cfSKarsten Keil unsigned char name[64]; 175960366cfSKarsten Keil int b_active; 176bc138ec4SAndreas Eversberg struct dsp_echo echo; 177960366cfSKarsten Keil int rx_disabled; /* what the user wants */ 178960366cfSKarsten Keil int rx_is_off; /* what the card is */ 179960366cfSKarsten Keil int tx_mix; 180960366cfSKarsten Keil struct dsp_tone tone; 181960366cfSKarsten Keil struct dsp_dtmf dtmf; 182960366cfSKarsten Keil int tx_volume, rx_volume; 183960366cfSKarsten Keil 184960366cfSKarsten Keil /* queue for sending frames */ 185960366cfSKarsten Keil struct work_struct workq; 186960366cfSKarsten Keil struct sk_buff_head sendq; 187960366cfSKarsten Keil int hdlc; /* if mode is hdlc */ 188960366cfSKarsten Keil int data_pending; /* currently an unconfirmed frame */ 189960366cfSKarsten Keil 190960366cfSKarsten Keil /* conference stuff */ 191960366cfSKarsten Keil u32 conf_id; 192960366cfSKarsten Keil struct dsp_conf *conf; 193960366cfSKarsten Keil struct dsp_conf_member 194960366cfSKarsten Keil *member; 195960366cfSKarsten Keil 196960366cfSKarsten Keil /* buffer stuff */ 197960366cfSKarsten Keil int rx_W; /* current write pos for data without timestamp */ 198960366cfSKarsten Keil int rx_R; /* current read pos for transmit clock */ 199960366cfSKarsten Keil int rx_init; /* if set, pointers will be adjusted first */ 200960366cfSKarsten Keil int tx_W; /* current write pos for transmit data */ 201960366cfSKarsten Keil int tx_R; /* current read pos for transmit clock */ 202960366cfSKarsten Keil int rx_delay[MAX_SECONDS_JITTER_CHECK]; 203960366cfSKarsten Keil int tx_delay[MAX_SECONDS_JITTER_CHECK]; 204960366cfSKarsten Keil u8 tx_buff[CMX_BUFF_SIZE]; 205960366cfSKarsten Keil u8 rx_buff[CMX_BUFF_SIZE]; 206960366cfSKarsten Keil int last_tx; /* if set, we transmitted last poll interval */ 207960366cfSKarsten Keil int cmx_delay; /* initial delay of buffers, 208960366cfSKarsten Keil or 0 for dynamic jitter buffer */ 209960366cfSKarsten Keil int tx_dejitter; /* if set, dejitter tx buffer */ 210960366cfSKarsten Keil int tx_data; /* enables tx-data of CMX to upper layer */ 211960366cfSKarsten Keil 212960366cfSKarsten Keil /* hardware stuff */ 213960366cfSKarsten Keil struct dsp_features features; 214960366cfSKarsten Keil int features_rx_off; /* set if rx_off is featured */ 2158dd2f36fSAndreas Eversberg int features_fill_empty; /* set if fill_empty is featured */ 216960366cfSKarsten Keil int pcm_slot_rx; /* current PCM slot (or -1) */ 217960366cfSKarsten Keil int pcm_bank_rx; 218960366cfSKarsten Keil int pcm_slot_tx; 219960366cfSKarsten Keil int pcm_bank_tx; 220960366cfSKarsten Keil int hfc_conf; /* unique id of current conference (or -1) */ 221960366cfSKarsten Keil 222960366cfSKarsten Keil /* encryption stuff */ 223960366cfSKarsten Keil int bf_enable; 224960366cfSKarsten Keil u32 bf_p[18]; 225960366cfSKarsten Keil u32 bf_s[1024]; 226960366cfSKarsten Keil int bf_crypt_pos; 227960366cfSKarsten Keil u8 bf_data_in[9]; 228960366cfSKarsten Keil u8 bf_crypt_out[9]; 229960366cfSKarsten Keil int bf_decrypt_in_pos; 230960366cfSKarsten Keil int bf_decrypt_out_pos; 231960366cfSKarsten Keil u8 bf_crypt_inring[16]; 232960366cfSKarsten Keil u8 bf_data_out[9]; 233960366cfSKarsten Keil int bf_sync; 234960366cfSKarsten Keil 235960366cfSKarsten Keil struct dsp_pipeline 236960366cfSKarsten Keil pipeline; 237960366cfSKarsten Keil }; 238960366cfSKarsten Keil 239960366cfSKarsten Keil /* functions */ 240960366cfSKarsten Keil 241960366cfSKarsten Keil extern void dsp_change_volume(struct sk_buff *skb, int volume); 242960366cfSKarsten Keil 243960366cfSKarsten Keil extern struct list_head dsp_ilist; 244960366cfSKarsten Keil extern struct list_head conf_ilist; 245960366cfSKarsten Keil extern void dsp_cmx_debug(struct dsp *dsp); 246960366cfSKarsten Keil extern void dsp_cmx_hardware(struct dsp_conf *conf, struct dsp *dsp); 247960366cfSKarsten Keil extern int dsp_cmx_conf(struct dsp *dsp, u32 conf_id); 248960366cfSKarsten Keil extern void dsp_cmx_receive(struct dsp *dsp, struct sk_buff *skb); 249960366cfSKarsten Keil extern void dsp_cmx_hdlc(struct dsp *dsp, struct sk_buff *skb); 250*1696ec86SNathan Chancellor extern void dsp_cmx_send(struct timer_list *arg); 251960366cfSKarsten Keil extern void dsp_cmx_transmit(struct dsp *dsp, struct sk_buff *skb); 252960366cfSKarsten Keil extern int dsp_cmx_del_conf_member(struct dsp *dsp); 253960366cfSKarsten Keil extern int dsp_cmx_del_conf(struct dsp_conf *conf); 254960366cfSKarsten Keil 255960366cfSKarsten Keil extern void dsp_dtmf_goertzel_init(struct dsp *dsp); 256960366cfSKarsten Keil extern void dsp_dtmf_hardware(struct dsp *dsp); 257960366cfSKarsten Keil extern u8 *dsp_dtmf_goertzel_decode(struct dsp *dsp, u8 *data, int len, 258960366cfSKarsten Keil int fmt); 259960366cfSKarsten Keil 260960366cfSKarsten Keil extern int dsp_tone(struct dsp *dsp, int tone); 261960366cfSKarsten Keil extern void dsp_tone_copy(struct dsp *dsp, u8 *data, int len); 262e313ac12SKees Cook extern void dsp_tone_timeout(struct timer_list *t); 263960366cfSKarsten Keil 264960366cfSKarsten Keil extern void dsp_bf_encrypt(struct dsp *dsp, u8 *data, int len); 265960366cfSKarsten Keil extern void dsp_bf_decrypt(struct dsp *dsp, u8 *data, int len); 266960366cfSKarsten Keil extern int dsp_bf_init(struct dsp *dsp, const u8 *key, unsigned int keylen); 267960366cfSKarsten Keil extern void dsp_bf_cleanup(struct dsp *dsp); 268960366cfSKarsten Keil 269960366cfSKarsten Keil extern int dsp_pipeline_module_init(void); 270960366cfSKarsten Keil extern void dsp_pipeline_module_exit(void); 271960366cfSKarsten Keil extern int dsp_pipeline_init(struct dsp_pipeline *pipeline); 272960366cfSKarsten Keil extern void dsp_pipeline_destroy(struct dsp_pipeline *pipeline); 273960366cfSKarsten Keil extern int dsp_pipeline_build(struct dsp_pipeline *pipeline, const char *cfg); 274960366cfSKarsten Keil extern void dsp_pipeline_process_tx(struct dsp_pipeline *pipeline, u8 *data, 275960366cfSKarsten Keil int len); 276960366cfSKarsten Keil extern void dsp_pipeline_process_rx(struct dsp_pipeline *pipeline, u8 *data, 2777cfa153dSAndreas Eversberg int len, unsigned int txlen); 278