Import 2.3.18pre1
[davej-history.git] / include / linux / hdlcdrv.h
blob2c7e5db589b7b89700ec2ce19344ce2705ae5954
1 /*
2 * hdlcdrv.h -- HDLC packet radio network driver.
3 * The Linux soundcard driver for 1200 baud and 9600 baud packet radio
4 * (C) 1996-1998 by Thomas Sailer, HB9JNX/AE4WA
5 */
7 #ifndef _HDLCDRV_H
8 #define _HDLCDRV_H
10 /* -------------------------------------------------------------------- */
12 * structs for the IOCTL commands
15 struct hdlcdrv_params {
16 int iobase;
17 int irq;
18 int dma;
19 int dma2;
20 int seriobase;
21 int pariobase;
22 int midiiobase;
23 };
25 struct hdlcdrv_channel_params {
26 int tx_delay; /* the transmitter keyup delay in 10ms units */
27 int tx_tail; /* the transmitter keyoff delay in 10ms units */
28 int slottime; /* the slottime in 10ms; usually 10 = 100ms */
29 int ppersist; /* the p-persistence 0..255 */
30 int fulldup; /* some driver do not support full duplex, setting */
31 /* this just makes them send even if DCD is on */
32 };
34 struct hdlcdrv_old_channel_state {
35 int ptt;
36 int dcd;
37 int ptt_keyed;
40 struct hdlcdrv_channel_state {
41 int ptt;
42 int dcd;
43 int ptt_keyed;
44 unsigned long tx_packets;
45 unsigned long tx_errors;
46 unsigned long rx_packets;
47 unsigned long rx_errors;
50 struct hdlcdrv_ioctl {
51 int cmd;
52 union {
53 struct hdlcdrv_params mp;
54 struct hdlcdrv_channel_params cp;
55 struct hdlcdrv_channel_state cs;
56 struct hdlcdrv_old_channel_state ocs;
57 unsigned int calibrate;
58 unsigned char bits;
59 char modename[128];
60 char drivername[32];
61 } data;
64 /* -------------------------------------------------------------------- */
67 * ioctl values
69 #define HDLCDRVCTL_GETMODEMPAR 0
70 #define HDLCDRVCTL_SETMODEMPAR 1
71 #define HDLCDRVCTL_MODEMPARMASK 2 /* not handled by hdlcdrv */
72 #define HDLCDRVCTL_GETCHANNELPAR 10
73 #define HDLCDRVCTL_SETCHANNELPAR 11
74 #define HDLCDRVCTL_OLDGETSTAT 20
75 #define HDLCDRVCTL_CALIBRATE 21
76 #define HDLCDRVCTL_GETSTAT 22
79 * these are mainly for debugging purposes
81 #define HDLCDRVCTL_GETSAMPLES 30
82 #define HDLCDRVCTL_GETBITS 31
85 * not handled by hdlcdrv, but by its depending drivers
87 #define HDLCDRVCTL_GETMODE 40
88 #define HDLCDRVCTL_SETMODE 41
89 #define HDLCDRVCTL_MODELIST 42
90 #define HDLCDRVCTL_DRIVERNAME 43
93 * mask of needed modem parameters, returned by HDLCDRVCTL_MODEMPARMASK
95 #define HDLCDRV_PARMASK_IOBASE (1<<0)
96 #define HDLCDRV_PARMASK_IRQ (1<<1)
97 #define HDLCDRV_PARMASK_DMA (1<<2)
98 #define HDLCDRV_PARMASK_DMA2 (1<<3)
99 #define HDLCDRV_PARMASK_SERIOBASE (1<<4)
100 #define HDLCDRV_PARMASK_PARIOBASE (1<<5)
101 #define HDLCDRV_PARMASK_MIDIIOBASE (1<<6)
103 /* -------------------------------------------------------------------- */
105 #ifdef __KERNEL__
107 #include <linux/netdevice.h>
108 #include <linux/if.h>
109 #include <linux/spinlock.h>
111 #define HDLCDRV_MAGIC 0x5ac6e778
112 #define HDLCDRV_IFNAMELEN 6
113 #define HDLCDRV_HDLCBUFFER 32 /* should be a power of 2 for speed reasons */
114 #define HDLCDRV_BITBUFFER 256 /* should be a power of 2 for speed reasons */
115 #undef HDLCDRV_LOOPBACK /* define for HDLC debugging purposes */
116 #define HDLCDRV_DEBUG
118 /* maximum packet length, excluding CRC */
119 #define HDLCDRV_MAXFLEN 400
122 struct hdlcdrv_hdlcbuffer {
123 spinlock_t lock;
124 unsigned rd, wr;
125 unsigned short buf[HDLCDRV_HDLCBUFFER];
128 #ifdef HDLCDRV_DEBUG
129 struct hdlcdrv_bitbuffer {
130 unsigned int rd;
131 unsigned int wr;
132 unsigned int shreg;
133 unsigned char buffer[HDLCDRV_BITBUFFER];
136 extern inline void hdlcdrv_add_bitbuffer(struct hdlcdrv_bitbuffer *buf,
137 unsigned int bit)
139 unsigned char new;
141 new = buf->shreg & 1;
142 buf->shreg >>= 1;
143 buf->shreg |= (!!bit) << 7;
144 if (new) {
145 buf->buffer[buf->wr] = buf->shreg;
146 buf->wr = (buf->wr+1) % sizeof(buf->buffer);
147 buf->shreg = 0x80;
151 extern inline void hdlcdrv_add_bitbuffer_word(struct hdlcdrv_bitbuffer *buf,
152 unsigned int bits)
154 buf->buffer[buf->wr] = bits & 0xff;
155 buf->wr = (buf->wr+1) % sizeof(buf->buffer);
156 buf->buffer[buf->wr] = (bits >> 8) & 0xff;
157 buf->wr = (buf->wr+1) % sizeof(buf->buffer);
160 #endif /* HDLCDRV_DEBUG */
162 /* -------------------------------------------------------------------- */
164 * Information that need to be kept for each driver.
167 struct hdlcdrv_ops {
169 * first some informations needed by the hdlcdrv routines
171 const char *drvname;
172 const char *drvinfo;
174 * the routines called by the hdlcdrv routines
176 int (*open)(struct net_device *);
177 int (*close)(struct net_device *);
178 int (*ioctl)(struct net_device *, struct ifreq *,
179 struct hdlcdrv_ioctl *, int);
182 struct hdlcdrv_state {
183 int magic;
185 char ifname[HDLCDRV_IFNAMELEN];
187 const struct hdlcdrv_ops *ops;
189 struct {
190 int bitrate;
191 } par;
193 struct hdlcdrv_pttoutput {
194 int dma2;
195 int seriobase;
196 int pariobase;
197 int midiiobase;
198 unsigned int flags;
199 } ptt_out;
201 struct hdlcdrv_channel_params ch_params;
203 struct hdlcdrv_hdlcrx {
204 struct hdlcdrv_hdlcbuffer hbuf;
205 int in_hdlc_rx;
206 /* 0 = sync hunt, != 0 receiving */
207 int rx_state;
208 unsigned int bitstream;
209 unsigned int bitbuf;
210 int numbits;
211 unsigned char dcd;
213 int len;
214 unsigned char *bp;
215 unsigned char buffer[HDLCDRV_MAXFLEN+2];
216 } hdlcrx;
218 struct hdlcdrv_hdlctx {
219 struct hdlcdrv_hdlcbuffer hbuf;
220 int in_hdlc_tx;
222 * 0 = send flags
223 * 1 = send txtail (flags)
224 * 2 = send packet
226 int tx_state;
227 int numflags;
228 unsigned int bitstream;
229 unsigned char ptt;
230 int calibrate;
231 int slotcnt;
233 unsigned int bitbuf;
234 int numbits;
236 int len;
237 unsigned char *bp;
238 unsigned char buffer[HDLCDRV_MAXFLEN+2];
239 } hdlctx;
241 #ifdef HDLCDRV_DEBUG
242 struct hdlcdrv_bitbuffer bitbuf_channel;
243 struct hdlcdrv_bitbuffer bitbuf_hdlc;
244 #endif /* HDLCDRV_DEBUG */
246 #if LINUX_VERSION_CODE < 0x20119
247 struct enet_statistics stats;
248 #else
249 struct net_device_stats stats;
250 #endif
251 int ptt_keyed;
253 struct sk_buff_head send_queue; /* Packets awaiting transmission */
257 /* -------------------------------------------------------------------- */
259 extern inline int hdlcdrv_hbuf_full(struct hdlcdrv_hdlcbuffer *hb)
261 unsigned long flags;
262 int ret;
264 spin_lock_irqsave(&hb->lock, flags);
265 ret = !((HDLCDRV_HDLCBUFFER - 1 + hb->rd - hb->wr) % HDLCDRV_HDLCBUFFER);
266 spin_unlock_irqrestore(&hb->lock, flags);
267 return ret;
270 /* -------------------------------------------------------------------- */
272 extern inline int hdlcdrv_hbuf_empty(struct hdlcdrv_hdlcbuffer *hb)
274 unsigned long flags;
275 int ret;
277 spin_lock_irqsave(&hb->lock, flags);
278 ret = (hb->rd == hb->wr);
279 spin_unlock_irqrestore(&hb->lock, flags);
280 return ret;
283 /* -------------------------------------------------------------------- */
285 extern inline unsigned short hdlcdrv_hbuf_get(struct hdlcdrv_hdlcbuffer *hb)
287 unsigned long flags;
288 unsigned short val;
289 unsigned newr;
291 spin_lock_irqsave(&hb->lock, flags);
292 if (hb->rd == hb->wr)
293 val = 0;
294 else {
295 newr = (hb->rd+1) % HDLCDRV_HDLCBUFFER;
296 val = hb->buf[hb->rd];
297 hb->rd = newr;
299 spin_unlock_irqrestore(&hb->lock, flags);
300 return val;
303 /* -------------------------------------------------------------------- */
305 extern inline void hdlcdrv_hbuf_put(struct hdlcdrv_hdlcbuffer *hb,
306 unsigned short val)
308 unsigned newp;
309 unsigned long flags;
311 spin_lock_irqsave(&hb->lock, flags);
312 newp = (hb->wr+1) % HDLCDRV_HDLCBUFFER;
313 if (newp != hb->rd) {
314 hb->buf[hb->wr] = val & 0xffff;
315 hb->wr = newp;
317 spin_unlock_irqrestore(&hb->lock, flags);
320 /* -------------------------------------------------------------------- */
322 extern inline void hdlcdrv_putbits(struct hdlcdrv_state *s, unsigned int bits)
324 hdlcdrv_hbuf_put(&s->hdlcrx.hbuf, bits);
327 extern inline unsigned int hdlcdrv_getbits(struct hdlcdrv_state *s)
329 unsigned int ret;
331 if (hdlcdrv_hbuf_empty(&s->hdlctx.hbuf)) {
332 if (s->hdlctx.calibrate > 0)
333 s->hdlctx.calibrate--;
334 else
335 s->hdlctx.ptt = 0;
336 ret = 0;
337 } else
338 ret = hdlcdrv_hbuf_get(&s->hdlctx.hbuf);
339 #ifdef HDLCDRV_LOOPBACK
340 hdlcdrv_hbuf_put(&s->hdlcrx.hbuf, ret);
341 #endif /* HDLCDRV_LOOPBACK */
342 return ret;
345 extern inline void hdlcdrv_channelbit(struct hdlcdrv_state *s, unsigned int bit)
347 #ifdef HDLCDRV_DEBUG
348 hdlcdrv_add_bitbuffer(&s->bitbuf_channel, bit);
349 #endif /* HDLCDRV_DEBUG */
352 extern inline void hdlcdrv_setdcd(struct hdlcdrv_state *s, int dcd)
354 s->hdlcrx.dcd = !!dcd;
357 extern inline int hdlcdrv_ptt(struct hdlcdrv_state *s)
359 return s->hdlctx.ptt || (s->hdlctx.calibrate > 0);
362 /* -------------------------------------------------------------------- */
364 void hdlcdrv_receiver(struct net_device *, struct hdlcdrv_state *);
365 void hdlcdrv_transmitter(struct net_device *, struct hdlcdrv_state *);
366 void hdlcdrv_arbitrate(struct net_device *, struct hdlcdrv_state *);
367 int hdlcdrv_register_hdlcdrv(struct net_device *dev, const struct hdlcdrv_ops *ops,
368 unsigned int privsize, char *ifname,
369 unsigned int baseaddr, unsigned int irq,
370 unsigned int dma);
371 int hdlcdrv_unregister_hdlcdrv(struct net_device *dev);
373 /* -------------------------------------------------------------------- */
377 #endif /* __KERNEL__ */
379 /* -------------------------------------------------------------------- */
381 #endif /* _HDLCDRV_H */
383 /* -------------------------------------------------------------------- */