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