| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 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 |
|
| 42 |
#define DRING_SIZE (1 << 7) |
| 43 |
#define DRING_MASK (DRING_SIZE-1) |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
#undef CONFIG_VOICEBUS_SYSFS |
| 49 |
|
| 50 |
|
| 51 |
#undef CONFIG_VOICEBUS_TIMER |
| 52 |
|
| 53 |
|
| 54 |
#undef VOICEBUS_NET_DEBUG |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
#define CONFIG_VOICEBUS_INTERRUPT |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 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 |
|
| 74 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
enum voicebus_mode { |
| 136 |
NORMAL = 0, |
| 137 |
BOOT = 1, |
| 138 |
HX8 = 2, |
| 139 |
}; |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 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 |