Debian Codegraph @

drivers/dahdi/xpp/xpd.h

raw symbols SCIP
1 #ifndef XPD_H
2 #define XPD_H
3
4 /*
5 * Written by Oron Peled <[email protected]>
6 * Copyright (C) 2004-2006, Xorcom
7 *
8 * All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 */
25
26 #include "xdefs.h"
27 #include "xproto.h"
28
29 #ifdef __KERNEL__
30 #include <linux/kernel.h>
31 #include <linux/device.h>
32 #include <linux/version.h>
33 #include <asm/atomic.h>
34 #include <linux/slab.h>
35 #include <linux/semaphore.h>
36 #include <linux/moduleparam.h>
37 #endif /* __KERNEL__ */
38
39 #include <dahdi/kernel.h>
40
41 #ifdef __KERNEL__
42
43 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
44 /*
45 * FIXME: Kludge for 2.6.19
46 * bool is now defined as a proper boolean type (gcc _Bool)
47 * but the command line parsing framework handles it as int.
48 */
49 #define DEF_PARM_BOOL(name, init, perm, desc) \
50 int name = init; \
51 module_param(name, bool, perm); \
52 MODULE_PARM_DESC(name, desc " [default " #init "]")
53 #else
54 #define DEF_PARM_BOOL(name, init, perm, desc) \
55 bool name = init; \
56 module_param(name, bool, perm); \
57 MODULE_PARM_DESC(name, desc " [default " #init "]")
58 #endif
59
60 #define DEF_PARM(type, name, init, perm, desc) \
61 type name = init; \
62 module_param(name, type, perm); \
63 MODULE_PARM_DESC(name, desc " [default " #init "]")
64
65 #define DEF_ARRAY(type, name, count, init, desc) \
66 unsigned int name ## _num_values; \
67 type name[count] = {[0 ... ((count)-1)] = init}; \
68 module_param_array(name, type, &name ## _num_values, 0644); \
69 MODULE_PARM_DESC(name, desc " ( 1-" __MODULE_STRING(count) ")")
70 #endif // __KERNEL__
71
72 #define CARD_DESC_MAGIC 0xca9dde5c
73
74 struct card_desc_struct {
75 struct list_head card_list;
76 u32 magic;
77 struct unit_descriptor unit_descriptor;
78 };
79
80 typedef enum xpd_direction {
81 TO_PSTN = 0,
82 TO_PHONE = 1,
83 } xpd_direction_t;
84
85 #ifdef __KERNEL__
86
87 /*
88 * XPD statistics counters
89 */
90 enum {
91 XPD_N_PCM_READ,
92 XPD_N_PCM_WRITE,
93 XPD_N_RECV_ERRORS,
94 };
95
96 #define XPD_COUNTER(xpd, counter) ((xpd)->counters[XPD_N_ ## counter])
97
98 #define C_(x) [ XPD_N_ ## x ] = { #x }
99
100 /* yucky, make an instance so we can size it... */
101 static struct xpd_counters {
102 char *name;
103 } xpd_counters[] = {
104 C_(PCM_READ), C_(PCM_WRITE), C_(RECV_ERRORS),};
105
106 #undef C_
107
108 #define XPD_COUNTER_MAX (sizeof(xpd_counters)/sizeof(xpd_counters[0]))
109
110 enum xpd_state {
111 XPD_STATE_START,
112 XPD_STATE_INIT_REGS,
113 XPD_STATE_READY,
114 XPD_STATE_NOHW,
115 };
116
117 bool xpd_setstate(xpd_t *xpd, enum xpd_state newstate);
118 const char *xpd_statename(enum xpd_state st);
119
120 #define PHONEDEV(xpd) ((xpd)->phonedev)
121 #define IS_PHONEDEV(xpd) (PHONEDEV(xpd).phoneops)
122
123 struct phonedev {
124 const struct phoneops *phoneops; /* Card level operations */
125 struct dahdi_span span;
126 struct dahdi_chan *chans[32];
127 #define XPD_CHAN(xpd, chan) (PHONEDEV(xpd).chans[(chan)])
128 struct dahdi_echocan_state *ec[32];
129
130 int channels;
131 xpd_direction_t direction; /* TO_PHONE, TO_PSTN */
132 xpp_line_t no_pcm; /* Temporary: disable PCM (for USB-1) */
133 xpp_line_t offhook_state; /* chip state: 0 - ONHOOK, 1 - OFHOOK */
134 xpp_line_t oht_pcm_pass; /* Transfer on-hook PCM */
135 /* Voice Mail Waiting Indication: */
136 unsigned int msg_waiting[CHANNELS_PERXPD];
137 xpp_line_t digital_outputs; /* 0 - no, 1 - yes */
138 xpp_line_t digital_inputs; /* 0 - no, 1 - yes */
139 xpp_line_t digital_signalling; /* BRI signalling channels */
140 uint timing_priority; /* from 'span' directives in chan_dahdi.conf */
141
142 /* Assure atomicity of changes to pcm_len and wanted_pcm_mask */
143 spinlock_t lock_recompute_pcm;
144 /* maintained by card drivers */
145 uint pcm_len; /* allocation length of PCM packet (dynamic) */
146 xpp_line_t wanted_pcm_mask;
147 xpp_line_t silence_pcm; /* inject silence during next tick */
148 xpp_line_t mute_dtmf;
149
150 bool ringing[CHANNELS_PERXPD];
151
152 atomic_t dahdi_registered; /* Am I fully registered with dahdi */
153 atomic_t open_counter; /* Number of open channels */
154
155 /* Echo cancelation */
156 u_char ec_chunk1[CHANNELS_PERXPD][DAHDI_CHUNKSIZE];
157 u_char ec_chunk2[CHANNELS_PERXPD][DAHDI_CHUNKSIZE];
158 };
159
160 /*
161 * An XPD is a single Xorcom Protocol Device
162 */
163 struct xpd {
164 char xpdname[XPD_NAMELEN];
165 struct phonedev phonedev;
166 struct unit_descriptor unit_descriptor;
167 #define XPD_HW(xpd) ((xpd)->unit_descriptor)
168
169 const struct xops *xops;
170 xpd_type_t xpd_type;
171 const char *type_name;
172 int subunits; /* all siblings */
173 enum xpd_state xpd_state;
174 struct device xpd_dev;
175 #define dev_to_xpd(dev) container_of(dev, struct xpd, xpd_dev)
176 struct kref kref;
177 #define kref_to_xpd(k) container_of(k, struct xpd, kref)
178
179 xbus_t *xbus; /* The XBUS we are connected to */
180 struct device *echocancel;
181
182 spinlock_t lock;
183
184 int flags;
185 unsigned long blink_mode; /* bitmask of blinking ports */
186 #define DEFAULT_LED_PERIOD (1000/8) /* in tick */
187
188 #ifdef CONFIG_PROC_FS
189 struct proc_dir_entry *proc_xpd_dir;
190 struct proc_dir_entry *proc_xpd_summary;
191 #endif
192
193 int counters[XPD_COUNTER_MAX];
194
195 const xproto_table_t *xproto; /* Card level protocol table */
196 void *priv; /* Card level private data */
197 bool card_present;
198 reg_cmd_t requested_reply;
199 reg_cmd_t last_reply;
200
201 unsigned long last_response; /* in jiffies */
202 unsigned xbus_idx; /* index in xbus->xpds[] */
203 struct xpd_addr addr;
204 struct list_head xpd_list;
205 unsigned int timer_count;
206 };
207
208 #define for_each_line(xpd, i) \
209 for ((i) = 0; (i) < PHONEDEV(xpd).channels; (i)++)
210 #define IS_BRI(xpd) ((xpd)->xpd_type == XPD_TYPE_BRI)
211 #define TICK_TOLERANCE 500 /* usec */
212
213 #ifdef DEBUG_SYNC_PARPORT
214 void xbus_flip_bit(xbus_t *xbus, unsigned int bitnum0, unsigned int bitnum1);
215 #else
216 #define xbus_flip_bit(xbus, bitnum0, bitnum1)
217 #endif
218
219 static inline void *my_kzalloc(size_t size, gfp_t flags)
220 {
221 void *p;
222
223 p = kmalloc(size, flags);
224 if (p)
225 memset(p, 0, size);
226 return p;
227 }
228
229 struct xpd_driver {
230 xpd_type_t xpd_type;
231
232 struct device_driver driver;
233 #define driver_to_xpd_driver(driver) \
234 container_of(driver, struct xpd_driver, driver)
235 };
236
237 int xpd_driver_register(struct device_driver *driver);
238 void xpd_driver_unregister(struct device_driver *driver);
239 xpd_t *get_xpd(const char *msg, xpd_t *xpd);
240 void put_xpd(const char *msg, xpd_t *xpd);
241 int refcount_xpd(xpd_t *xpd);
242
243 #endif
244
245 #endif /* XPD_H */