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
10 /* -------------------------------------------------------------------- */
12 * structs for the IOCTL commands
15 struct hdlcdrv_params
{
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 */
34 struct hdlcdrv_old_channel_state
{
40 struct hdlcdrv_channel_state
{
44 unsigned long tx_packets
;
45 unsigned long tx_errors
;
46 unsigned long rx_packets
;
47 unsigned long rx_errors
;
50 struct hdlcdrv_ioctl
{
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
;
64 /* -------------------------------------------------------------------- */
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 /* -------------------------------------------------------------------- */
107 #include <linux/netdevice.h>
108 #include <linux/if.h>
109 #include <linux/spinlock.h>
111 #define HDLCDRV_MAGIC 0x5ac6e778
112 #define HDLCDRV_HDLCBUFFER 32 /* should be a power of 2 for speed reasons */
113 #define HDLCDRV_BITBUFFER 256 /* should be a power of 2 for speed reasons */
114 #undef HDLCDRV_LOOPBACK /* define for HDLC debugging purposes */
115 #define HDLCDRV_DEBUG
117 /* maximum packet length, excluding CRC */
118 #define HDLCDRV_MAXFLEN 400
121 struct hdlcdrv_hdlcbuffer
{
124 unsigned short buf
[HDLCDRV_HDLCBUFFER
];
128 struct hdlcdrv_bitbuffer
{
132 unsigned char buffer
[HDLCDRV_BITBUFFER
];
135 static inline void hdlcdrv_add_bitbuffer(struct hdlcdrv_bitbuffer
*buf
,
140 new = buf
->shreg
& 1;
142 buf
->shreg
|= (!!bit
) << 7;
144 buf
->buffer
[buf
->wr
] = buf
->shreg
;
145 buf
->wr
= (buf
->wr
+1) % sizeof(buf
->buffer
);
150 static inline void hdlcdrv_add_bitbuffer_word(struct hdlcdrv_bitbuffer
*buf
,
153 buf
->buffer
[buf
->wr
] = bits
& 0xff;
154 buf
->wr
= (buf
->wr
+1) % sizeof(buf
->buffer
);
155 buf
->buffer
[buf
->wr
] = (bits
>> 8) & 0xff;
156 buf
->wr
= (buf
->wr
+1) % sizeof(buf
->buffer
);
159 #endif /* HDLCDRV_DEBUG */
161 /* -------------------------------------------------------------------- */
163 * Information that need to be kept for each driver.
168 * first some informations needed by the hdlcdrv routines
173 * the routines called by the hdlcdrv routines
175 int (*open
)(struct net_device
*);
176 int (*close
)(struct net_device
*);
177 int (*ioctl
)(struct net_device
*, struct ifreq
*,
178 struct hdlcdrv_ioctl
*, int);
181 struct hdlcdrv_state
{
185 const struct hdlcdrv_ops
*ops
;
191 struct hdlcdrv_pttoutput
{
199 struct hdlcdrv_channel_params ch_params
;
201 struct hdlcdrv_hdlcrx
{
202 struct hdlcdrv_hdlcbuffer hbuf
;
203 unsigned long in_hdlc_rx
;
204 /* 0 = sync hunt, != 0 receiving */
206 unsigned int bitstream
;
213 unsigned char buffer
[HDLCDRV_MAXFLEN
+2];
216 struct hdlcdrv_hdlctx
{
217 struct hdlcdrv_hdlcbuffer hbuf
;
221 * 1 = send txtail (flags)
226 unsigned int bitstream
;
236 unsigned char buffer
[HDLCDRV_MAXFLEN
+2];
240 struct hdlcdrv_bitbuffer bitbuf_channel
;
241 struct hdlcdrv_bitbuffer bitbuf_hdlc
;
242 #endif /* HDLCDRV_DEBUG */
244 struct net_device_stats stats
;
247 /* queued skb for transmission */
252 /* -------------------------------------------------------------------- */
254 static inline int hdlcdrv_hbuf_full(struct hdlcdrv_hdlcbuffer
*hb
)
259 spin_lock_irqsave(&hb
->lock
, flags
);
260 ret
= !((HDLCDRV_HDLCBUFFER
- 1 + hb
->rd
- hb
->wr
) % HDLCDRV_HDLCBUFFER
);
261 spin_unlock_irqrestore(&hb
->lock
, flags
);
265 /* -------------------------------------------------------------------- */
267 static inline int hdlcdrv_hbuf_empty(struct hdlcdrv_hdlcbuffer
*hb
)
272 spin_lock_irqsave(&hb
->lock
, flags
);
273 ret
= (hb
->rd
== hb
->wr
);
274 spin_unlock_irqrestore(&hb
->lock
, flags
);
278 /* -------------------------------------------------------------------- */
280 static inline unsigned short hdlcdrv_hbuf_get(struct hdlcdrv_hdlcbuffer
*hb
)
286 spin_lock_irqsave(&hb
->lock
, flags
);
287 if (hb
->rd
== hb
->wr
)
290 newr
= (hb
->rd
+1) % HDLCDRV_HDLCBUFFER
;
291 val
= hb
->buf
[hb
->rd
];
294 spin_unlock_irqrestore(&hb
->lock
, flags
);
298 /* -------------------------------------------------------------------- */
300 static inline void hdlcdrv_hbuf_put(struct hdlcdrv_hdlcbuffer
*hb
,
306 spin_lock_irqsave(&hb
->lock
, flags
);
307 newp
= (hb
->wr
+1) % HDLCDRV_HDLCBUFFER
;
308 if (newp
!= hb
->rd
) {
309 hb
->buf
[hb
->wr
] = val
& 0xffff;
312 spin_unlock_irqrestore(&hb
->lock
, flags
);
315 /* -------------------------------------------------------------------- */
317 static inline void hdlcdrv_putbits(struct hdlcdrv_state
*s
, unsigned int bits
)
319 hdlcdrv_hbuf_put(&s
->hdlcrx
.hbuf
, bits
);
322 static inline unsigned int hdlcdrv_getbits(struct hdlcdrv_state
*s
)
326 if (hdlcdrv_hbuf_empty(&s
->hdlctx
.hbuf
)) {
327 if (s
->hdlctx
.calibrate
> 0)
328 s
->hdlctx
.calibrate
--;
333 ret
= hdlcdrv_hbuf_get(&s
->hdlctx
.hbuf
);
334 #ifdef HDLCDRV_LOOPBACK
335 hdlcdrv_hbuf_put(&s
->hdlcrx
.hbuf
, ret
);
336 #endif /* HDLCDRV_LOOPBACK */
340 static inline void hdlcdrv_channelbit(struct hdlcdrv_state
*s
, unsigned int bit
)
343 hdlcdrv_add_bitbuffer(&s
->bitbuf_channel
, bit
);
344 #endif /* HDLCDRV_DEBUG */
347 static inline void hdlcdrv_setdcd(struct hdlcdrv_state
*s
, int dcd
)
349 s
->hdlcrx
.dcd
= !!dcd
;
352 static inline int hdlcdrv_ptt(struct hdlcdrv_state
*s
)
354 return s
->hdlctx
.ptt
|| (s
->hdlctx
.calibrate
> 0);
357 /* -------------------------------------------------------------------- */
359 void hdlcdrv_receiver(struct net_device
*, struct hdlcdrv_state
*);
360 void hdlcdrv_transmitter(struct net_device
*, struct hdlcdrv_state
*);
361 void hdlcdrv_arbitrate(struct net_device
*, struct hdlcdrv_state
*);
362 struct net_device
*hdlcdrv_register(const struct hdlcdrv_ops
*ops
,
363 unsigned int privsize
, const char *ifname
,
364 unsigned int baseaddr
, unsigned int irq
,
366 void hdlcdrv_unregister(struct net_device
*dev
);
368 /* -------------------------------------------------------------------- */
372 #endif /* __KERNEL__ */
374 /* -------------------------------------------------------------------- */
376 #endif /* _HDLCDRV_H */
378 /* -------------------------------------------------------------------- */