2
* Written by Oron Peled <oron@actcom.co.il>
3
* Copyright (C) 2004-2006, Xorcom
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.
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.
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.
25
#include <linux/wait.h>
26
#include <linux/interrupt.h> /* for tasklets */
28
#include "xframe_queue.h"
32
#define XFRAME_DATASIZE 512
34
/* forward declarations */
35
struct xbus_workqueue;
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);
50
* XBUS statistics counters
65
#define XBUS_COUNTER(xbus, counter) ((xbus)->counters[XBUS_N_ ## counter])
67
#define C_(x) [ XBUS_N_ ## x ] = { #x }
69
/* yucky, make an instance so we can size it... */
70
static struct xbus_counters {
87
#define XBUS_COUNTER_MAX ARRAY_SIZE(xbus_counters)
89
struct xbus_transport {
93
bool transport_running; /* Hardware is functional */
94
atomic_t transport_refcount;
95
wait_queue_head_t transport_unused;
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)
103
struct xbus_ops *transportops_get(xbus_t *xbus);
104
void transportops_put(xbus_t *xbus);
107
* Encapsulate all poll related data of a single xbus.
109
struct xbus_workqueue {
111
struct workqueue_struct *wq;
112
struct work_struct xpds_init_work;
114
struct list_head card_list;
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;
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.
128
xframe_t *get_xframe(struct xframe_queue *q);
129
void put_xframe(struct xframe_queue *q, xframe_t *xframe);
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))
136
xbus_t *get_xbus(uint num);
137
void put_xbus(xbus_t *xbus);
140
* An xbus is a transport layer for Xorcom Protocol commands
143
char busname[XBUS_NAMELEN]; /* set by xbus_new() */
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;
152
struct xpd *xpds[MAX_XPDS];
154
struct xframe_queue command_queue;
155
wait_queue_head_t command_queue_empty;
157
struct xframe_queue send_pool; /* empty xframes for send */
158
struct xframe_queue receive_pool; /* empty xframes for receive */
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];
167
enum sync_mode sync_mode;
168
struct timer_list command_timer;
169
unsigned int xbus_frag_count;
170
struct xframe_queue pcm_tospan;
172
struct xpp_ticker ticker; /* for tick rate */
173
struct xpp_drift drift; /* for tick offset */
175
atomic_t pcm_rx_counter;
176
unsigned int global_counter;
179
struct device astribank;
180
#define dev_to_xbus(dev) container_of(dev, struct xbus, astribank)
183
atomic_t xbus_ref_count; /* How many need this struct? */
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) */
194
#define SAMPLE_SIZE 1000
195
int sample_ticks[SAMPLE_SIZE];
200
struct xbus_workqueue *worker;
206
int sync_adjustment_offset;
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)
216
struct dentry *debugfs_dir;
217
struct dentry *debugfs_file;
218
struct debugfs_data *debugfs_data;
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;
229
int counters[XBUS_COUNTER_MAX];
233
#define XFRAME_MAGIC 123456L
236
unsigned long xframe_magic;
237
struct list_head frame_list;
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 */
246
byte *packets; /* max XFRAME_DATASIZE */
251
void xframe_init(xbus_t *xbus, xframe_t *xframe, void *buf, size_t maxsize, void *priv);
253
#define XFRAME_LEN(frame) atomic_read(&(frame)->frame_len)
255
int xbus_core_init(void); /* Initializer */
256
void xbus_core_shutdown(void); /* Terminator */
259
/* Debugfs handling */
260
int xbus_log(xbus_t *xbus, xpd_t *xpd, int direction, const void *buf, unsigned long len);
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);
268
* Return pointer to next packet slot in the frame
269
* or NULL if the frame is full.
271
xpacket_t *xframe_next_packet(xframe_t *xframe, int len);
276
* Map: unit+subunit <--> index in xbus->xpds[]
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)
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);
292
void xbus_populate(void *data);
295
int xbus_register_xpd(xbus_t *xbus, xpd_t *xpd);
296
int xbus_unregister_xpd(xbus_t *xbus, xpd_t *xpd);
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);
304
#endif /* XBUS_CORE_H */