~ubuntu-branches/ubuntu/quantal/zaptel/quantal

« back to all changes in this revision

Viewing changes to kernel/xpp/xbus-core.h

  • Committer: Bazaar Package Importer
  • Author(s): Tzafrir Cohen
  • Date: 2008-08-28 22:58:23 UTC
  • mfrom: (11.1.11 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080828225823-r8bdunirm8hmc76m
Tags: 1:1.4.11~dfsg-2
* Patch xpp_fxs_power: Fixed an issue with hook detection of the Astribank
  FXS module.
* Don't fail init.d script if fxotune fails. This may happen if running it
  when Asterisk is already running.
* Bump standards version to 3.8.0.0 .
* Ignore false lintian warning ("m-a a-i" has "a a").
* Patch xpp_fxo_cid_always: do always pass PCM if that's what the user
  asked.
* Patch vzaphfc_proc_root_dir: fix vzaphfc on 2.6.26.
* Patch wcte12xp_flags: Proper time for irq save flags.
* Patch headers_2627: Fix location of semaphore.h for 2.6.27 .
* Patch xpp_fxs_dtmf_leak: Don't play DTMFs to the wrong channel.
* Patch wctdm_fix_alarm: Fix sending channel alarms.
* Patch device_class_2626: Fix building 2.6.26 (Closes: #493397).
* Using dh_lintian for lintian overrides, hence requiring debhelper 6.0.7.
* Lintian: we know we have direct changes. Too bad we're half-upstream :-(
* Fix doc-base section names. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Written by Oron Peled <oron@actcom.co.il>
 
3
 * Copyright (C) 2004-2006, Xorcom
 
4
 *
 
5
 * All rights reserved.
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
20
 *
 
21
 */
 
22
#ifndef XBUS_CORE_H
 
23
#define XBUS_CORE_H
 
24
 
 
25
#include <linux/wait.h>
 
26
#include <linux/interrupt.h>    /* for tasklets */
 
27
#include "xpd.h"
 
28
#include "xframe_queue.h"
 
29
#include "xbus-pcm.h"
 
30
 
 
31
#define MAX_BUSES               32
 
32
#define XFRAME_DATASIZE         512
 
33
 
 
34
/* forward declarations */
 
35
struct xbus_workqueue;
 
36
#ifdef XPP_DEBUGFS
 
37
struct debugfs_data;
 
38
#endif
 
39
 
 
40
#ifdef  __KERNEL__
 
41
 
 
42
struct xbus_ops {
 
43
        int (*xframe_send_pcm)(xbus_t *xbus, xframe_t *xframe);
 
44
        int (*xframe_send_cmd)(xbus_t *xbus, xframe_t *xframe);
 
45
        xframe_t *(*alloc_xframe)(xbus_t *xbus, gfp_t gfp_flags);
 
46
        void (*free_xframe)(xbus_t *xbus, xframe_t *xframe);
 
47
};
 
48
 
 
49
/*
 
50
 * XBUS statistics counters
 
51
 */
 
52
enum {
 
53
        XBUS_N_UNITS,
 
54
        XBUS_N_TX_XFRAME_PCM,
 
55
        XBUS_N_RX_XFRAME_PCM,
 
56
        XBUS_N_TX_PACK_PCM,
 
57
        XBUS_N_RX_PACK_PCM,
 
58
        XBUS_N_TX_BYTES,
 
59
        XBUS_N_RX_BYTES,
 
60
        XBUS_N_TX_PCM_FRAG,
 
61
        XBUS_N_RX_CMD,
 
62
        XBUS_N_TX_CMD,
 
63
};
 
64
 
 
65
#define XBUS_COUNTER(xbus, counter)     ((xbus)->counters[XBUS_N_ ## counter])
 
66
 
 
67
#define C_(x)   [ XBUS_N_ ## x ] = { #x }
 
68
 
 
69
/* yucky, make an instance so we can size it... */
 
70
static struct xbus_counters {
 
71
        char    *name;
 
72
} xbus_counters[] = {
 
73
        C_(UNITS),
 
74
        C_(TX_XFRAME_PCM),
 
75
        C_(RX_XFRAME_PCM),
 
76
        C_(TX_PACK_PCM),
 
77
        C_(RX_PACK_PCM),
 
78
        C_(TX_BYTES),
 
79
        C_(RX_BYTES),
 
80
        C_(TX_PCM_FRAG),
 
81
        C_(RX_CMD),
 
82
        C_(TX_CMD),
 
83
};
 
84
 
 
85
#undef C_
 
86
 
 
87
#define XBUS_COUNTER_MAX        ARRAY_SIZE(xbus_counters)
 
88
 
 
89
struct xbus_transport {
 
90
        struct xbus_ops         *ops;
 
91
        void                    *priv;
 
92
        ushort                  max_send_size;
 
93
        bool                    transport_running;      /* Hardware is functional */
 
94
        atomic_t                transport_refcount;
 
95
        wait_queue_head_t       transport_unused;
 
96
        spinlock_t              lock;
 
97
};
 
98
 
 
99
#define MAX_SEND_SIZE(xbus)     ((xbus)->transport.max_send_size)
 
100
#define TRANSPORT_RUNNING(xbus) ((xbus)->transport.transport_running)
 
101
#define TRANSPORT_EXIST(xbus)   ((xbus)->transport.ops != NULL)
 
102
 
 
103
struct xbus_ops *transportops_get(xbus_t *xbus);
 
104
void transportops_put(xbus_t *xbus);
 
105
 
 
106
/*
 
107
 * Encapsulate all poll related data of a single xbus.
 
108
 */
 
109
struct xbus_workqueue {
 
110
        xbus_t                  *xbus;
 
111
        struct workqueue_struct *wq;
 
112
        struct work_struct      xpds_init_work;
 
113
        bool                    xpds_init_done;
 
114
        struct list_head        card_list;
 
115
        int                     num_units;
 
116
        int                     num_units_initialized;
 
117
        wait_queue_head_t       wait_for_xpd_initialization;
 
118
        struct proc_dir_entry   *proc_xbus_waitfor_xpds;
 
119
        spinlock_t              worker_lock;
 
120
};
 
121
 
 
122
/*
 
123
 * Allocate/Free an xframe from pools of empty xframes.
 
124
 * Calls to {get,put}_xframe are wrapped in
 
125
 * the macros bellow, so we take/return it
 
126
 * to the correct pool.
 
127
 */
 
128
xframe_t *get_xframe(struct xframe_queue *q);
 
129
void put_xframe(struct xframe_queue *q, xframe_t *xframe);
 
130
 
 
131
#define ALLOC_SEND_XFRAME(xbus) get_xframe(&(xbus)->send_pool)
 
132
#define ALLOC_RECV_XFRAME(xbus) get_xframe(&(xbus)->receive_pool)
 
133
#define FREE_SEND_XFRAME(xbus, xframe)  put_xframe(&(xbus)->send_pool, (xframe))
 
134
#define FREE_RECV_XFRAME(xbus, xframe)  put_xframe(&(xbus)->receive_pool, (xframe))
 
135
 
 
136
xbus_t *get_xbus(uint num);
 
137
void put_xbus(xbus_t *xbus);
 
138
 
 
139
/*
 
140
 * An xbus is a transport layer for Xorcom Protocol commands
 
141
 */
 
142
struct xbus {
 
143
        char                    busname[XBUS_NAMELEN];  /* set by xbus_new() */
 
144
 
 
145
        /* low-level bus drivers set these 2 fields */
 
146
        char                    location[XBUS_DESCLEN];
 
147
        char                    label[LABEL_SIZE];
 
148
        byte                    revision;               /* Protocol revision */
 
149
        struct xbus_transport   transport;
 
150
 
 
151
        int                     num;
 
152
        struct xpd              *xpds[MAX_XPDS];
 
153
 
 
154
        struct xframe_queue     command_queue;
 
155
        wait_queue_head_t       command_queue_empty;
 
156
 
 
157
        struct xframe_queue     send_pool;              /* empty xframes for send */
 
158
        struct xframe_queue     receive_pool;           /* empty xframes for receive */
 
159
 
 
160
        /* tasklet processing */
 
161
        struct xframe_queue     receive_queue;
 
162
        struct tasklet_struct   receive_tasklet;
 
163
        int                     cpu_rcv_intr[NR_CPUS];
 
164
        int                     cpu_rcv_tasklet[NR_CPUS];
 
165
 
 
166
        bool                    self_ticking;
 
167
        enum sync_mode          sync_mode;
 
168
        struct timer_list       command_timer;
 
169
        unsigned int            xbus_frag_count;
 
170
        struct xframe_queue     pcm_tospan;
 
171
 
 
172
        struct xpp_ticker       ticker;         /* for tick rate */
 
173
        struct xpp_drift        drift;          /* for tick offset */
 
174
 
 
175
        atomic_t                pcm_rx_counter;
 
176
        unsigned int            global_counter;
 
177
 
 
178
        /* Device-Model */
 
179
        struct device           astribank;
 
180
#define dev_to_xbus(dev)        container_of(dev, struct xbus, astribank)
 
181
 
 
182
        spinlock_t              lock;
 
183
        atomic_t                xbus_ref_count; /* How many need this struct? */
 
184
 
 
185
        /* PCM metrics */
 
186
        struct timeval          last_tx_sync;
 
187
        struct timeval          last_rx_sync;
 
188
        unsigned long           max_tx_sync;
 
189
        unsigned long           min_tx_sync;
 
190
        unsigned long           max_rx_sync;
 
191
        unsigned long           min_rx_sync;
 
192
        unsigned long           max_rx_process;         /* packet processing time (usec) */
 
193
#ifdef  SAMPLE_TICKS
 
194
#define SAMPLE_SIZE     1000
 
195
        int                     sample_ticks[SAMPLE_SIZE];
 
196
        bool                    sample_running;
 
197
        int                     sample_pos;
 
198
#endif
 
199
 
 
200
        struct xbus_workqueue   *worker;
 
201
 
 
202
        /*
 
203
         * Sync adjustment
 
204
         */
 
205
        int                     sync_adjustment;
 
206
        int                     sync_adjustment_offset;
 
207
        long                    pll_updated_at;
 
208
 
 
209
        struct  rw_semaphore    in_use;
 
210
#define XBUS_GET(xbus)  down_read_trylock(&(xbus)->in_use)
 
211
#define XBUS_PUT(xbus)  up_read(&(xbus)->in_use)
 
212
 
 
213
        int                     num_xpds;
 
214
 
 
215
#ifdef  XPP_DEBUGFS
 
216
        struct dentry           *debugfs_dir;
 
217
        struct dentry           *debugfs_file;
 
218
        struct debugfs_data     *debugfs_data;
 
219
#endif
 
220
#ifdef CONFIG_PROC_FS
 
221
        struct proc_dir_entry   *proc_xbus_dir;
 
222
        struct proc_dir_entry   *proc_xbus_summary;
 
223
#ifdef  PROTOCOL_DEBUG
 
224
        struct proc_dir_entry   *proc_xbus_command;
 
225
#endif
 
226
#endif
 
227
 
 
228
        /* statistics */
 
229
        int             counters[XBUS_COUNTER_MAX];
 
230
};
 
231
#endif
 
232
 
 
233
#define XFRAME_MAGIC    123456L
 
234
 
 
235
struct xframe {
 
236
        unsigned long           xframe_magic;
 
237
        struct list_head        frame_list;
 
238
        atomic_t                frame_len;
 
239
        xbus_t                  *xbus;
 
240
        struct timeval          tv_created;
 
241
        struct timeval          tv_queued;
 
242
        struct timeval          tv_submitted;
 
243
        struct timeval          tv_received;
 
244
        /* filled by transport layer */
 
245
        size_t                  frame_maxlen;
 
246
        byte                    *packets;       /* max XFRAME_DATASIZE */
 
247
        byte                    *first_free;
 
248
        void                    *priv;
 
249
};
 
250
 
 
251
void xframe_init(xbus_t *xbus, xframe_t *xframe, void *buf, size_t maxsize, void *priv);
 
252
 
 
253
#define XFRAME_LEN(frame)       atomic_read(&(frame)->frame_len)
 
254
 
 
255
int xbus_core_init(void);               /* Initializer */
 
256
void xbus_core_shutdown(void);          /* Terminator */
 
257
 
 
258
#ifdef XPP_DEBUGFS
 
259
/* Debugfs handling */
 
260
int xbus_log(xbus_t *xbus, xpd_t *xpd, int direction, const void *buf, unsigned long len);
 
261
#endif
 
262
 
 
263
/* Frame handling */
 
264
void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe, int debug);
 
265
int send_cmd_frame(xbus_t *xbus, xframe_t *xframe);
 
266
 
 
267
/*
 
268
 * Return pointer to next packet slot in the frame
 
269
 * or NULL if the frame is full.
 
270
 */
 
271
xpacket_t *xframe_next_packet(xframe_t *xframe, int len);
 
272
 
 
273
/* XBUS handling */
 
274
 
 
275
/*
 
276
 * Map: unit+subunit <--> index in xbus->xpds[]
 
277
 */
 
278
#define XPD_IDX(unit,subunit)   ((unit) * MAX_SUBUNIT + (subunit))
 
279
#define XBUS_UNIT(idx)          ((idx) / MAX_SUBUNIT)
 
280
#define XBUS_SUBUNIT(idx)       ((idx) % MAX_SUBUNIT)
 
281
 
 
282
xpd_t   *xpd_of(const xbus_t *xbus, int xpd_num);
 
283
xpd_t   *xpd_byaddr(const xbus_t *xbus, uint unit, uint subunit);
 
284
xbus_t  *xbus_new(struct xbus_ops *ops, ushort max_send_size, void *priv);
 
285
void xbus_remove(xbus_t *xbus);
 
286
int xbus_activate(xbus_t *xbus);
 
287
void xbus_disconnect(xbus_t *xbus);
 
288
void xbus_receive_xframe(xbus_t *xbus, xframe_t *xframe);
 
289
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
 
290
void xbus_populate(struct work_struct *work);
 
291
#else
 
292
void xbus_populate(void *data);
 
293
#endif
 
294
 
 
295
int xbus_register_xpd(xbus_t *xbus, xpd_t *xpd);
 
296
int xbus_unregister_xpd(xbus_t *xbus, xpd_t *xpd);
 
297
 
 
298
/* sysfs */
 
299
int register_xpp_bus(void);
 
300
void unregister_xpp_bus(void);
 
301
int xbus_sysfs_create(xbus_t *xbus);
 
302
void xbus_sysfs_remove(xbus_t *xbus);
 
303
 
 
304
#endif  /* XBUS_CORE_H */
 
305