OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [include/] [linux/] [hdlcdrv.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1633 jcastillo
/*
2
 * hdlcdrv.h  -- HDLC packet radio network driver.
3
 * The Linux soundcard driver for 1200 baud and 9600 baud packet radio
4
 * (C) 1996 by Thomas Sailer, HB9JNX/AE4WA
5
 */
6
 
7
#ifndef _HDLCDRV_H
8
#define _HDLCDRV_H
9
 
10
#include <linux/version.h>
11
#include <linux/sockios.h>
12
#include <linux/version.h>
13
#if LINUX_VERSION_CODE < 0x20119
14
#include <linux/if_ether.h>
15
#endif
16
#include <linux/netdevice.h>
17
 
18
/* -------------------------------------------------------------------- */
19
/*
20
 * structs for the IOCTL commands
21
 */
22
 
23
struct hdlcdrv_params {
24
        int iobase;
25
        int irq;
26
        int dma;
27
        int dma2;
28
        int seriobase;
29
        int pariobase;
30
        int midiiobase;
31
};
32
 
33
struct hdlcdrv_channel_params {
34
        int tx_delay;  /* the transmitter keyup delay in 10ms units */
35
        int tx_tail;   /* the transmitter keyoff delay in 10ms units */
36
        int slottime;  /* the slottime in 10ms; usually 10 = 100ms */
37
        int ppersist;  /* the p-persistence 0..255 */
38
        int fulldup;   /* some driver do not support full duplex, setting */
39
                       /* this just makes them send even if DCD is on */
40
};
41
 
42
struct hdlcdrv_old_channel_state {
43
        int ptt;
44
        int dcd;
45
        int ptt_keyed;
46
#if LINUX_VERSION_CODE < 0x20100
47
        struct enet_statistics stats;
48
#endif
49
};
50
 
51
struct hdlcdrv_channel_state {
52
        int ptt;
53
        int dcd;
54
        int ptt_keyed;
55
        unsigned long tx_packets;
56
        unsigned long tx_errors;
57
        unsigned long rx_packets;
58
        unsigned long rx_errors;
59
};
60
 
61
struct hdlcdrv_ioctl {
62
        int cmd;
63
        union {
64
                struct hdlcdrv_params mp;
65
                struct hdlcdrv_channel_params cp;
66
                struct hdlcdrv_channel_state cs;
67
                struct hdlcdrv_old_channel_state ocs;
68
                unsigned int calibrate;
69
                unsigned char bits;
70
                char modename[128];
71
                char drivername[32];
72
        } data;
73
};
74
 
75
/* -------------------------------------------------------------------- */
76
 
77
/*
78
 * ioctl values
79
 */
80
#define HDLCDRVCTL_GETMODEMPAR       0
81
#define HDLCDRVCTL_SETMODEMPAR       1
82
#define HDLCDRVCTL_MODEMPARMASK      2  /* not handled by hdlcdrv */
83
#define HDLCDRVCTL_GETCHANNELPAR    10
84
#define HDLCDRVCTL_SETCHANNELPAR    11
85
#define HDLCDRVCTL_OLDGETSTAT       20
86
#define HDLCDRVCTL_CALIBRATE        21
87
#define HDLCDRVCTL_GETSTAT          22
88
 
89
/*
90
 * these are mainly for debugging purposes
91
 */
92
#define HDLCDRVCTL_GETSAMPLES       30
93
#define HDLCDRVCTL_GETBITS          31
94
 
95
/*
96
 * not handled by hdlcdrv, but by its depending drivers
97
 */
98
#define HDLCDRVCTL_GETMODE          40
99
#define HDLCDRVCTL_SETMODE          41
100
#define HDLCDRVCTL_MODELIST         42
101
#define HDLCDRVCTL_DRIVERNAME       43
102
 
103
/*
104
 * mask of needed modem parameters, returned by HDLCDRVCTL_MODEMPARMASK
105
 */
106
#define HDLCDRV_PARMASK_IOBASE      (1<<0)
107
#define HDLCDRV_PARMASK_IRQ         (1<<1)
108
#define HDLCDRV_PARMASK_DMA         (1<<2)
109
#define HDLCDRV_PARMASK_DMA2        (1<<3)
110
#define HDLCDRV_PARMASK_SERIOBASE   (1<<4)
111
#define HDLCDRV_PARMASK_PARIOBASE   (1<<5)
112
#define HDLCDRV_PARMASK_MIDIIOBASE  (1<<6)
113
 
114
/* -------------------------------------------------------------------- */
115
 
116
#ifdef __KERNEL__
117
 
118
#define HDLCDRV_MAGIC      0x5ac6e778
119
#define HDLCDRV_IFNAMELEN    6
120
#define HDLCDRV_HDLCBUFFER  32 /* should be a power of 2 for speed reasons */
121
#define HDLCDRV_BITBUFFER  256 /* should be a power of 2 for speed reasons */
122
#undef HDLCDRV_LOOPBACK  /* define for HDLC debugging purposes */
123
#define HDLCDRV_DEBUG
124
 
125
/* maximum packet length, excluding CRC */
126
#define HDLCDRV_MAXFLEN             400 
127
 
128
 
129
struct hdlcdrv_hdlcbuffer {
130
        unsigned rd, wr;
131
        unsigned short buf[HDLCDRV_HDLCBUFFER];
132
};
133
 
134
#ifdef HDLCDRV_DEBUG
135
struct hdlcdrv_bitbuffer {
136
        unsigned int rd;
137
        unsigned int wr;
138
        unsigned int shreg;
139
        unsigned char buffer[HDLCDRV_BITBUFFER];
140
};
141
 
142
extern inline void hdlcdrv_add_bitbuffer(struct hdlcdrv_bitbuffer *buf,
143
                                         unsigned int bit)
144
{
145
        unsigned char new;
146
 
147
        new = buf->shreg & 1;
148
        buf->shreg >>= 1;
149
        buf->shreg |= (!!bit) << 7;
150
        if (new) {
151
                buf->buffer[buf->wr] = buf->shreg;
152
                buf->wr = (buf->wr+1) % sizeof(buf->buffer);
153
                buf->shreg = 0x80;
154
        }
155
}
156
 
157
extern inline void hdlcdrv_add_bitbuffer_word(struct hdlcdrv_bitbuffer *buf,
158
                                              unsigned int bits)
159
{
160
        buf->buffer[buf->wr] = bits & 0xff;
161
        buf->wr = (buf->wr+1) % sizeof(buf->buffer);
162
        buf->buffer[buf->wr] = (bits >> 8) & 0xff;
163
        buf->wr = (buf->wr+1) % sizeof(buf->buffer);
164
 
165
}
166
#endif /* HDLCDRV_DEBUG */
167
 
168
/* -------------------------------------------------------------------- */
169
/*
170
 * Information that need to be kept for each driver.
171
 */
172
 
173
struct hdlcdrv_ops {
174
        /*
175
         * first some informations needed by the hdlcdrv routines
176
         */
177
        const char *drvname;
178
        const char *drvinfo;
179
        /*
180
         * the routines called by the hdlcdrv routines
181
         */
182
        int (*open)(struct device *);
183
        int (*close)(struct device *);
184
        int (*ioctl)(struct device *, struct ifreq *,
185
                     struct hdlcdrv_ioctl *, int);
186
};
187
 
188
struct hdlcdrv_state {
189
        int magic;
190
 
191
        char ifname[HDLCDRV_IFNAMELEN];
192
 
193
        const struct hdlcdrv_ops *ops;
194
 
195
        struct {
196
                int bitrate;
197
        } par;
198
 
199
        struct hdlcdrv_pttoutput {
200
                int dma2;
201
                int seriobase;
202
                int pariobase;
203
                int midiiobase;
204
                unsigned int flags;
205
        } ptt_out;
206
 
207
        struct hdlcdrv_channel_params ch_params;
208
 
209
        struct hdlcdrv_hdlcrx {
210
                struct hdlcdrv_hdlcbuffer hbuf;
211
                int in_hdlc_rx;
212
                /* 0 = sync hunt, != 0 receiving */
213
                int rx_state;
214
                unsigned int bitstream;
215
                unsigned int bitbuf;
216
                int numbits;
217
                unsigned char dcd;
218
 
219
                int len;
220
                unsigned char *bp;
221
                unsigned char buffer[HDLCDRV_MAXFLEN+2];
222
        } hdlcrx;
223
 
224
        struct hdlcdrv_hdlctx {
225
                struct hdlcdrv_hdlcbuffer hbuf;
226
                int in_hdlc_tx;
227
                /*
228
                 * 0 = send flags
229
                 * 1 = send txtail (flags)
230
                 * 2 = send packet
231
                 */
232
                int tx_state;
233
                int numflags;
234
                unsigned int bitstream;
235
                unsigned char ptt;
236
                int calibrate;
237
                int slotcnt;
238
 
239
                unsigned int bitbuf;
240
                int numbits;
241
 
242
                int len;
243
                unsigned char *bp;
244
                unsigned char buffer[HDLCDRV_MAXFLEN+2];
245
        } hdlctx;
246
 
247
#ifdef HDLCDRV_DEBUG
248
        struct hdlcdrv_bitbuffer bitbuf_channel;
249
        struct hdlcdrv_bitbuffer bitbuf_hdlc;
250
#endif /* HDLCDRV_DEBUG */
251
 
252
#if LINUX_VERSION_CODE < 0x20119
253
        struct enet_statistics stats;
254
#else
255
        struct net_device_stats stats;
256
#endif
257
        int ptt_keyed;
258
 
259
        struct sk_buff_head send_queue;  /* Packets awaiting transmission */
260
};
261
 
262
 
263
/* -------------------------------------------------------------------- */
264
 
265
extern inline int hdlcdrv_hbuf_full(struct hdlcdrv_hdlcbuffer *hb)
266
{
267
        return !((HDLCDRV_HDLCBUFFER - 1 + hb->rd - hb->wr)
268
                 % HDLCDRV_HDLCBUFFER);
269
}
270
 
271
/* -------------------------------------------------------------------- */
272
 
273
extern inline int hdlcdrv_hbuf_empty(struct hdlcdrv_hdlcbuffer *hb)
274
{
275
        return hb->rd == hb->wr;
276
}
277
 
278
/* -------------------------------------------------------------------- */
279
 
280
extern inline unsigned short hdlcdrv_hbuf_get(struct hdlcdrv_hdlcbuffer *hb)
281
{
282
        unsigned newr;
283
        unsigned short val;
284
        unsigned long flags;
285
 
286
        if (hb->rd == hb->wr)
287
                return 0;
288
        save_flags(flags);
289
        cli();
290
        newr = (hb->rd+1) % HDLCDRV_HDLCBUFFER;
291
        val = hb->buf[hb->rd];
292
        hb->rd = newr;
293
        restore_flags(flags);
294
        return val;
295
}
296
 
297
/* -------------------------------------------------------------------- */
298
 
299
extern inline void hdlcdrv_hbuf_put(struct hdlcdrv_hdlcbuffer *hb,
300
                                    unsigned short val)
301
{
302
        unsigned newp;
303
        unsigned long flags;
304
 
305
        save_flags(flags);
306
        cli();
307
        newp = (hb->wr+1) % HDLCDRV_HDLCBUFFER;
308
        if (newp != hb->rd) {
309
                hb->buf[hb->wr] = val & 0xffff;
310
                hb->wr = newp;
311
        }
312
        restore_flags(flags);
313
}
314
 
315
/* -------------------------------------------------------------------- */
316
 
317
extern inline void hdlcdrv_putbits(struct hdlcdrv_state *s, unsigned int bits)
318
{
319
        hdlcdrv_hbuf_put(&s->hdlcrx.hbuf, bits);
320
}
321
 
322
extern inline unsigned int hdlcdrv_getbits(struct hdlcdrv_state *s)
323
{
324
        unsigned int ret;
325
 
326
        if (hdlcdrv_hbuf_empty(&s->hdlctx.hbuf)) {
327
                if (s->hdlctx.calibrate > 0)
328
                        s->hdlctx.calibrate--;
329
                else
330
                        s->hdlctx.ptt = 0;
331
                ret = 0;
332
        } else
333
                ret = hdlcdrv_hbuf_get(&s->hdlctx.hbuf);
334
#ifdef HDLCDRV_LOOPBACK
335
        hdlcdrv_hbuf_put(&s->hdlcrx.hbuf, ret);
336
#endif /* HDLCDRV_LOOPBACK */
337
        return ret;
338
}
339
 
340
extern inline void hdlcdrv_channelbit(struct hdlcdrv_state *s, unsigned int bit)
341
{
342
#ifdef HDLCDRV_DEBUG
343
        hdlcdrv_add_bitbuffer(&s->bitbuf_channel, bit);
344
#endif /* HDLCDRV_DEBUG */
345
}
346
 
347
extern inline void hdlcdrv_setdcd(struct hdlcdrv_state *s, int dcd)
348
{
349
        s->hdlcrx.dcd = !!dcd;
350
}
351
 
352
extern inline int hdlcdrv_ptt(struct hdlcdrv_state *s)
353
{
354
        return s->hdlctx.ptt || (s->hdlctx.calibrate > 0);
355
}
356
 
357
/* -------------------------------------------------------------------- */
358
 
359
void hdlcdrv_receiver(struct device *, struct hdlcdrv_state *);
360
void hdlcdrv_transmitter(struct device *, struct hdlcdrv_state *);
361
void hdlcdrv_arbitrate(struct device *, struct hdlcdrv_state *);
362
int hdlcdrv_register_hdlcdrv(struct device *dev, const struct hdlcdrv_ops *ops,
363
                             unsigned int privsize, char *ifname,
364
                             unsigned int baseaddr, unsigned int irq,
365
                             unsigned int dma);
366
int hdlcdrv_unregister_hdlcdrv(struct device *dev);
367
 
368
/* -------------------------------------------------------------------- */
369
 
370
 
371
 
372
#endif /* __KERNEL__ */
373
 
374
/* -------------------------------------------------------------------- */
375
 
376
#endif /* _HDLCDRV_H */
377
 
378
/* -------------------------------------------------------------------- */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.