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 #ifdef CONFIG_VOICEBUS_DISABLE_ASPM
68 #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)
69 #include <linux/pci-aspm.h>
70 #endif
71 #endif
72
73 /* Define this to use a FIFO for the software echocan reference.
74 * (experimental) */
75 #undef CONFIG_VOICEBUS_ECREFERENCE
76
77 #ifdef CONFIG_VOICEBUS_ECREFERENCE
78
79 struct dahdi_fifo;
80 unsigned int __dahdi_fifo_put(struct dahdi_fifo *fifo, u8 *data, size_t size);
81 unsigned int __dahdi_fifo_get(struct dahdi_fifo *fifo, u8 *data, size_t size);
82 void dahdi_fifo_free(struct dahdi_fifo *fifo);
83 struct dahdi_fifo *dahdi_fifo_alloc(size_t maxsize, gfp_t alloc_flags);
84
85 #endif
86
87 #ifdef VOICEBUS_NET_DEBUG
88 #include <linux/skbuff.h>
89 #include <linux/netdevice.h>
90 #include <linux/etherdevice.h>
91 #endif
92
93 struct voicebus;
94
95 struct vbb {
96 u8 data[VOICEBUS_SFRAME_SIZE];
97 struct list_head entry;
98 dma_addr_t dma_addr;
99 };
100
101 struct voicebus_operations {
102 void (*handle_receive)(struct voicebus *vb, struct list_head *buffers);
103 void (*handle_transmit)(struct voicebus *vb, struct list_head *buffers);
104 void (*handle_error)(struct voicebus *vb);
105 };
106
107 /**
108 * struct voicebus_descriptor_list - A single descriptor list.
109 */
110 struct voicebus_descriptor_list {
111 struct voicebus_descriptor *desc;
112 unsigned int head;
113 unsigned int tail;
114 void *pending[DRING_SIZE];
115 dma_addr_t desc_dma;
116 unsigned long count;
117 unsigned int padding;
118 };
119
120 /* Bit definitions for struct voicebus.flags */
121 #define VOICEBUS_SHUTDOWN 0
122 #define VOICEBUS_STOP 1
123 #define VOICEBUS_STOPPED 2
124 #define VOICEBUS_LATENCY_LOCKED 3
125 #define VOICEBUS_HARD_UNDERRUN 4
126
127 /**
128 * voicebus_mode
129 *
130 * NORMAL: For non-hx8 boards. Uses idle_buffers.
131 * BOOT: For hx8 boards. For sending single packets at a time.
132 * HX8: Normal operating mode for Hx8 Boards. Does not use
133 * idle_buffers.
134 */
135 enum voicebus_mode {
136 NORMAL = 0,
137 BOOT = 1,
138 HX8 = 2,
139 };
140
141 /**
142 * struct voicebus - Represents physical interface to voicebus card.
143 *
144 * @tx_complete: only used in the tasklet to temporarily hold complete tx
145 * buffers.
146 */
147 struct voicebus {
148 struct pci_dev *pdev;
149 spinlock_t lock;
150 struct voicebus_descriptor_list rxd;
151 struct voicebus_descriptor_list txd;
152 u8 *idle_vbb;
153 dma_addr_t idle_vbb_dma_addr;
154 const int *debug;
155 void __iomem *iobase;
156 struct tasklet_struct tasklet;
157 enum voicebus_mode mode;
158
159 #if defined(CONFIG_VOICEBUS_INTERRUPT)
160 atomic_t deferred_disabled_count;
161 #endif
162
163 #if defined(CONFIG_VOICEBUS_TIMER)
164 struct timer_list timer;
165 #endif
166
167 struct work_struct underrun_work;
168 const struct voicebus_operations *ops;
169 unsigned long flags;
170 unsigned int min_tx_buffer_count;
171 unsigned int max_latency;
172 struct list_head tx_complete;
173 struct list_head free_rx;
174 struct dma_pool *pool;
175
176 #ifdef VOICEBUS_NET_DEBUG
177 struct sk_buff_head captured_packets;
178 struct net_device *netdev;
179 struct net_device_stats net_stats;
180 struct napi_struct napi;
181 atomic_t tx_seqnum;
182 atomic_t rx_seqnum;
183 #endif
184 };
185
186 int __voicebus_init(struct voicebus *vb, const char *board_name,
187 enum voicebus_mode mode);
188 void voicebus_release(struct voicebus *vb);
189 int voicebus_start(struct voicebus *vb);
190 void voicebus_stop(struct voicebus *vb);
191 void voicebus_quiesce(struct voicebus *vb);
192 int voicebus_transmit(struct voicebus *vb, struct vbb *vbb);
193 int voicebus_set_minlatency(struct voicebus *vb, unsigned int milliseconds);
194 int voicebus_current_latency(struct voicebus *vb);
195
196 static inline int voicebus_init(struct voicebus *vb, const char *board_name)
197 {
198 return __voicebus_init(vb, board_name, NORMAL);
199 }
200
201 static inline int
202 voicebus_boot_init(struct voicebus *vb, const char *board_name)
203 {
204 return __voicebus_init(vb, board_name, BOOT);
205 }
206
207 /**
208 * voicebus_lock_latency() - Do not increase the latency during underruns.
209 *
210 */
211 static inline void voicebus_lock_latency(struct voicebus *vb)
212 {
213 set_bit(VOICEBUS_LATENCY_LOCKED, &vb->flags);
214 }
215
216 /**
217 * voicebus_unlock_latency() - Bump up the latency during underruns.
218 *
219 */
220 static inline void voicebus_unlock_latency(struct voicebus *vb)
221 {
222 clear_bit(VOICEBUS_LATENCY_LOCKED, &vb->flags);
223 }
224
225 /**
226 * voicebus_is_latency_locked() - Return 1 if latency is currently locked.
227 *
228 */
229 static inline int voicebus_is_latency_locked(const struct voicebus *vb)
230 {
231 return test_bit(VOICEBUS_LATENCY_LOCKED, &vb->flags);
232 }
233
234 static inline void voicebus_set_normal_mode(struct voicebus *vb)
235 {
236 vb->mode = NORMAL;
237 }
238
239 static inline void voicebus_set_hx8_mode(struct voicebus *vb)
240 {
241 vb->mode = HX8;
242 }
243
244 /**
245 * voicebus_set_max_latency() - Set the maximum number of milliseconds the latency will be able to grow to.
246 */
247 static inline void
248 voicebus_set_maxlatency(struct voicebus *vb, unsigned int max_latency)
249 {
250 unsigned long flags;
251 spin_lock_irqsave(&vb->lock, flags);
252 vb->max_latency = clamp(max_latency,
253 vb->min_tx_buffer_count,
254 VOICEBUS_DEFAULT_MAXLATENCY);
255 spin_unlock_irqrestore(&vb->lock, flags);
256 }
257 #endif /* __VOICEBUS_H__ */