Debian Codegraph @

drivers/dahdi/xpp/xpd.h

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