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_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
{ 125 unsigned short buf
[HDLCDRV_HDLCBUFFER
]; 129 struct hdlcdrv_bitbuffer
{ 133 unsigned char buffer
[HDLCDRV_BITBUFFER
]; 136 extern inlinevoidhdlcdrv_add_bitbuffer(struct hdlcdrv_bitbuffer
*buf
, 143 buf
->shreg
|= (!!bit
) <<7; 145 buf
->buffer
[buf
->wr
] = buf
->shreg
; 146 buf
->wr
= (buf
->wr
+1) %sizeof(buf
->buffer
); 151 extern inlinevoidhdlcdrv_add_bitbuffer_word(struct hdlcdrv_bitbuffer
*buf
, 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. 169 * first some informations needed by the hdlcdrv routines 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
{ 185 char ifname
[HDLCDRV_IFNAMELEN
]; 187 const struct hdlcdrv_ops
*ops
; 193 struct hdlcdrv_pttoutput
{ 201 struct hdlcdrv_channel_params ch_params
; 203 struct hdlcdrv_hdlcrx
{ 204 struct hdlcdrv_hdlcbuffer hbuf
; 206 /* 0 = sync hunt, != 0 receiving */ 208 unsigned int bitstream
; 215 unsigned char buffer
[HDLCDRV_MAXFLEN
+2]; 218 struct hdlcdrv_hdlctx
{ 219 struct hdlcdrv_hdlcbuffer hbuf
; 223 * 1 = send txtail (flags) 228 unsigned int bitstream
; 238 unsigned char buffer
[HDLCDRV_MAXFLEN
+2]; 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
; 249 struct net_device_stats stats
; 253 struct sk_buff_head send_queue
;/* Packets awaiting transmission */ 257 /* -------------------------------------------------------------------- */ 259 extern inlineinthdlcdrv_hbuf_full(struct hdlcdrv_hdlcbuffer
*hb
) 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
); 270 /* -------------------------------------------------------------------- */ 272 extern inlineinthdlcdrv_hbuf_empty(struct hdlcdrv_hdlcbuffer
*hb
) 277 spin_lock_irqsave(&hb
->lock
, flags
); 278 ret
= (hb
->rd
== hb
->wr
); 279 spin_unlock_irqrestore(&hb
->lock
, flags
); 283 /* -------------------------------------------------------------------- */ 285 extern inlineunsigned shorthdlcdrv_hbuf_get(struct hdlcdrv_hdlcbuffer
*hb
) 291 spin_lock_irqsave(&hb
->lock
, flags
); 295 newr
= (hb
->rd
+1) % HDLCDRV_HDLCBUFFER
; 296 val
= hb
->buf
[hb
->rd
]; 299 spin_unlock_irqrestore(&hb
->lock
, flags
); 303 /* -------------------------------------------------------------------- */ 305 extern inlinevoidhdlcdrv_hbuf_put(struct hdlcdrv_hdlcbuffer
*hb
, 311 spin_lock_irqsave(&hb
->lock
, flags
); 312 newp
= (hb
->wr
+1) % HDLCDRV_HDLCBUFFER
; 314 hb
->buf
[hb
->wr
] = val
&0xffff; 317 spin_unlock_irqrestore(&hb
->lock
, flags
); 320 /* -------------------------------------------------------------------- */ 322 extern inlinevoidhdlcdrv_putbits(struct hdlcdrv_state
*s
,unsigned int bits
) 324 hdlcdrv_hbuf_put(&s
->hdlcrx
.hbuf
, bits
); 327 extern inlineunsigned inthdlcdrv_getbits(struct hdlcdrv_state
*s
) 331 if(hdlcdrv_hbuf_empty(&s
->hdlctx
.hbuf
)) { 332 if(s
->hdlctx
.calibrate
>0) 333 s
->hdlctx
.calibrate
--; 338 ret
=hdlcdrv_hbuf_get(&s
->hdlctx
.hbuf
); 339 #ifdef HDLCDRV_LOOPBACK 340 hdlcdrv_hbuf_put(&s
->hdlcrx
.hbuf
, ret
); 341 #endif/* HDLCDRV_LOOPBACK */ 345 extern inlinevoidhdlcdrv_channelbit(struct hdlcdrv_state
*s
,unsigned int bit
) 348 hdlcdrv_add_bitbuffer(&s
->bitbuf_channel
, bit
); 349 #endif/* HDLCDRV_DEBUG */ 352 extern inlinevoidhdlcdrv_setdcd(struct hdlcdrv_state
*s
,int dcd
) 354 s
->hdlcrx
.dcd
= !!dcd
; 357 extern inlineinthdlcdrv_ptt(struct hdlcdrv_state
*s
) 359 return s
->hdlctx
.ptt
|| (s
->hdlctx
.calibrate
>0); 362 /* -------------------------------------------------------------------- */ 364 voidhdlcdrv_receiver(struct net_device
*,struct hdlcdrv_state
*); 365 voidhdlcdrv_transmitter(struct net_device
*,struct hdlcdrv_state
*); 366 voidhdlcdrv_arbitrate(struct net_device
*,struct hdlcdrv_state
*); 367 inthdlcdrv_register_hdlcdrv(struct net_device
*dev
,const struct hdlcdrv_ops
*ops
, 368 unsigned int privsize
,char*ifname
, 369 unsigned int baseaddr
,unsigned int irq
, 371 inthdlcdrv_unregister_hdlcdrv(struct net_device
*dev
); 373 /* -------------------------------------------------------------------- */ 377 #endif/* __KERNEL__ */ 379 /* -------------------------------------------------------------------- */ 381 #endif/* _HDLCDRV_H */ 383 /* -------------------------------------------------------------------- */