Debian Codegraph @

drivers/dahdi/voicebus/voicebus.h

raw symbols SCIP
1 /*
2 * VoiceBus(tm) Interface Library.
3 *
4 * Written by Shaun Ruffell <[email protected]>
5 * and based on previous work by Mark Spencer <[email protected]>,
6 * Matthew Fredrickson <[email protected]>, and
7 * Michael Spiceland <[email protected]>
8 *
9 * Copyright (C) 2007-2010 Digium, Inc.
10 *
11 * All rights reserved.
12 *
13 */
14
15 /*
16 * See http://www.asterisk.org for more information about
17 * the Asterisk project. Please do not directly contact
18 * any of the maintainers of this project for assistance;
19 * the project provides a web site, mailing lists and IRC
20 * channels for your use.
21 *
22 * This program is free software, distributed under the terms of
23 * the GNU General Public License Version 2 as published by the
24 * Free Software Foundation. See the LICENSE file included with
25 * this program for more details.
26 */
27
28
29 #ifndef __VOICEBUS_H__
30 #define __VOICEBUS_H__
31
32 #include <linux/interrupt.h>
33
34
35 #define VOICEBUS_DEFAULT_LATENCY 3U
36 #define VOICEBUS_DEFAULT_MAXLATENCY 25U
37 #define VOICEBUS_MAXLATENCY_BUMP 6U
38
39 #define VOICEBUS_SFRAME_SIZE 1004U
40
41 /*! The number of descriptors in both the tx and rx descriptor ring. */
42 #define DRING_SIZE (1 << 7) /* Must be a power of 2 */
43 #define DRING_MASK (DRING_SIZE-1)
44
45 /* Define CONFIG_VOICEBUS_SYSFS to create some attributes under the pci device.
46 * This is disabled by default because it hasn't been tested on the full range
47 * of supported kernels. */
48 #undef CONFIG_VOICEBUS_SYSFS
49
50 /* Do not generate interrupts on this interface, but instead just poll it */
51 #undef CONFIG_VOICEBUS_TIMER
52
53 /* Define this in order to create a debugging network interface. */
54 #undef VOICEBUS_NET_DEBUG
55
56 /* Define this to only run the processing in an interrupt handler
57 * (and not tasklet). */
58 #define CONFIG_VOICEBUS_INTERRUPT
59
60 /*
61 * Enable the following definition in order to disable Active-State Power
62 * Management on the PCIe bridge for PCIe cards. This has been known to work
63 * around issues where the BIOS enables it on the cards even though the
64 * platform does not support it.
65 *
66 */
67 #undef CONFIG_VOICEBUS_DISABLE_ASPM
68
69 /* Define this to use a FIFO for the software echocan reference.
70 * (experimental) */
71 #undef CONFIG_VOICEBUS_ECREFERENCE
72
73 #ifdef CONFIG_VOICEBUS_ECREFERENCE
74
75 struct dahdi_fifo;
76 unsigned int __dahdi_fifo_put(struct dahdi_fifo *fifo, u8 *data, size_t size);
77 unsigned int __dahdi_fifo_get(struct dahdi_fifo *fifo, u8 *data, size_t size);
78 void dahdi_fifo_free(struct dahdi_fifo *fifo);
79 struct dahdi_fifo *dahdi_fifo_alloc(size_t maxsize, gfp_t alloc_flags);
80
81 #endif
82
83 #ifdef VOICEBUS_NET_DEBUG
84 #include <linux/skbuff.h>
85 #include <linux/netdevice.h>
86 #include <linux/etherdevice.h>
87 #endif
88
89 struct voicebus;
90
91 struct vbb {
92 u8 data[VOICEBUS_SFRAME_SIZE];
93 struct list_head entry;
94 dma_addr_t dma_addr;
95 };
96
97 struct voicebus_operations {
98 void (*handle_receive)(struct voicebus *vb, struct list_head *buffers);
99 void (*handle_transmit)(struct voicebus *vb, struct list_head *buffers);
100 void (*handle_error)(struct voicebus *vb);
101 };
102
103 /**
104 * struct voicebus_descriptor_list - A single descriptor list.
105 */
106 struct voicebus_descriptor_list {
107 struct voicebus_descriptor *desc;
108 unsigned int head;
109 unsigned int tail;
110 void *pending[DRING_SIZE];
111 dma_addr_t desc_dma;
112 unsigned long count;
113 unsigned int padding;
114 };
115
116 /* Bit definitions for struct voicebus.flags */
117 #define VOICEBUS_SHUTDOWN 0
118 #define VOICEBUS_STOP 1
119 #define VOICEBUS_STOPPED 2
120 #define VOICEBUS_LATENCY_LOCKED 3
121 #define VOICEBUS_HARD_UNDERRUN 4
122
123 /**
124 * voicebus_mode
125 *
126 * NORMAL: For non-hx8 boards. Uses idle_buffers.
127 * BOOT: For hx8 boards. For sending single packets at a time.
128 * HX8: Normal operating mode for Hx8 Boards. Does not use
129 * idle_buffers.
130 */
131 enum voicebus_mode {
132 NORMAL = 0,
133 BOOT = 1,
134 HX8 = 2,
135 };
136
137 /**
138 * struct voicebus - Represents physical interface to voicebus card.
139 *
140 * @tx_complete: only used in the tasklet to temporarily hold complete tx
141 * buffers.
142 */
143 struct voicebus {
144 struct pci_dev *pdev;
145 spinlock_t lock;
146 struct voicebus_descriptor_list rxd;
147 struct voicebus_descriptor_list txd;
148 u8 *idle_vbb;
149 dma_addr_t idle_vbb_dma_addr;
150 const int *debug;
151 void __iomem *iobase;
152 struct tasklet_struct tasklet;
153 enum voicebus_mode mode;
154
155 #if defined(CONFIG_VOICEBUS_INTERRUPT)
156 atomic_t deferred_disabled_count;
157 #endif
158
159 #if defined(CONFIG_VOICEBUS_TIMER)
160 struct timer_list timer;
161 #endif
162
163 struct work_struct underrun_work;
164 const struct voicebus_operations *ops;
165 unsigned long flags;
166 unsigned int min_tx_buffer_count;
167 unsigned int max_latency;
168 struct list_head tx_complete;
169 struct list_head free_rx;
170 struct dma_pool *pool;
171
172 #ifdef VOICEBUS_NET_DEBUG
173 struct sk_buff_head captured_packets;
174 struct net_device *netdev;
175 struct net_device_stats net_stats;
176 struct napi_struct napi;
177 atomic_t tx_seqnum;
178 atomic_t rx_seqnum;
179 #endif
180 };
181
182 int __voicebus_init(struct voicebus *vb, const char *board_name,
183 enum voicebus_mode mode);
184 void voicebus_release(struct voicebus *vb);
185 int voicebus_start(struct voicebus *vb);
186 void voicebus_stop(struct voicebus *vb);
187 void voicebus_quiesce(struct voicebus *vb);
188 int voicebus_transmit(struct voicebus *vb, struct vbb *vbb);
189 int voicebus_set_minlatency(struct voicebus *vb, unsigned int milliseconds);
190 int voicebus_current_latency(struct voicebus *vb);
191
192 static inline int voicebus_init(struct voicebus *vb, const char *board_name)
193 {
194 return __voicebus_init(vb, board_name, NORMAL);
195 }
196
197 static inline int
198 voicebus_boot_init(struct voicebus *vb, const char *board_name)
199 {
200 return __voicebus_init(vb, board_name, BOOT);
201 }
202
203 /**
204 * voicebus_lock_latency() - Do not increase the latency during underruns.
205 *
206 */
207 static inline void voicebus_lock_latency(struct voicebus *vb)
208 {
209 set_bit(VOICEBUS_LATENCY_LOCKED, &vb->flags);
210 }
211
212 /**
213 * voicebus_unlock_latency() - Bump up the latency during underruns.
214 *
215 */
216 static inline void voicebus_unlock_latency(struct voicebus *vb)
217 {
218 clear_bit(VOICEBUS_LATENCY_LOCKED, &vb->flags);
219 }
220
221 /**
222 * voicebus_is_latency_locked() - Return 1 if latency is currently locked.
223 *
224 */
225 static inline int voicebus_is_latency_locked(const struct voicebus *vb)
226 {
227 return test_bit(VOICEBUS_LATENCY_LOCKED, &vb->flags);
228 }
229
230 static inline void voicebus_set_normal_mode(struct voicebus *vb)
231 {
232 vb->mode = NORMAL;
233 }
234
235 static inline void voicebus_set_hx8_mode(struct voicebus *vb)
236 {
237 vb->mode = HX8;
238 }
239
240 /**
241 * voicebus_set_max_latency() - Set the maximum number of milliseconds the latency will be able to grow to.
242 */
243 static inline void
244 voicebus_set_maxlatency(struct voicebus *vb, unsigned int max_latency)
245 {
246 unsigned long flags;
247 spin_lock_irqsave(&vb->lock, flags);
248 vb->max_latency = clamp(max_latency,
249 vb->min_tx_buffer_count,
250 VOICEBUS_DEFAULT_MAXLATENCY);
251 spin_unlock_irqrestore(&vb->lock, flags);
252 }
253 #endif /* __VOICEBUS_H__ */