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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [include/] [linux/] [hdlcdrv.h] - Diff between revs 1765 and 1782

Only display areas with differences | Details | Blame | View Log

Rev 1765 Rev 1782
/*
/*
 * hdlcdrv.h  -- HDLC packet radio network driver.
 * hdlcdrv.h  -- HDLC packet radio network driver.
 * The Linux soundcard driver for 1200 baud and 9600 baud packet radio
 * The Linux soundcard driver for 1200 baud and 9600 baud packet radio
 * (C) 1996 by Thomas Sailer, HB9JNX/AE4WA
 * (C) 1996 by Thomas Sailer, HB9JNX/AE4WA
 */
 */
 
 
#ifndef _HDLCDRV_H
#ifndef _HDLCDRV_H
#define _HDLCDRV_H
#define _HDLCDRV_H
 
 
#include <linux/version.h>
#include <linux/version.h>
#include <linux/sockios.h>
#include <linux/sockios.h>
#include <linux/version.h>
#include <linux/version.h>
#if LINUX_VERSION_CODE < 0x20119
#if LINUX_VERSION_CODE < 0x20119
#include <linux/if_ether.h>
#include <linux/if_ether.h>
#endif
#endif
#include <linux/netdevice.h>
#include <linux/netdevice.h>
 
 
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
/*
/*
 * structs for the IOCTL commands
 * structs for the IOCTL commands
 */
 */
 
 
struct hdlcdrv_params {
struct hdlcdrv_params {
        int iobase;
        int iobase;
        int irq;
        int irq;
        int dma;
        int dma;
        int dma2;
        int dma2;
        int seriobase;
        int seriobase;
        int pariobase;
        int pariobase;
        int midiiobase;
        int midiiobase;
};
};
 
 
struct hdlcdrv_channel_params {
struct hdlcdrv_channel_params {
        int tx_delay;  /* the transmitter keyup delay in 10ms units */
        int tx_delay;  /* the transmitter keyup delay in 10ms units */
        int tx_tail;   /* the transmitter keyoff delay in 10ms units */
        int tx_tail;   /* the transmitter keyoff delay in 10ms units */
        int slottime;  /* the slottime in 10ms; usually 10 = 100ms */
        int slottime;  /* the slottime in 10ms; usually 10 = 100ms */
        int ppersist;  /* the p-persistence 0..255 */
        int ppersist;  /* the p-persistence 0..255 */
        int fulldup;   /* some driver do not support full duplex, setting */
        int fulldup;   /* some driver do not support full duplex, setting */
                       /* this just makes them send even if DCD is on */
                       /* this just makes them send even if DCD is on */
};
};
 
 
struct hdlcdrv_old_channel_state {
struct hdlcdrv_old_channel_state {
        int ptt;
        int ptt;
        int dcd;
        int dcd;
        int ptt_keyed;
        int ptt_keyed;
#if LINUX_VERSION_CODE < 0x20100
#if LINUX_VERSION_CODE < 0x20100
        struct enet_statistics stats;
        struct enet_statistics stats;
#endif
#endif
};
};
 
 
struct hdlcdrv_channel_state {
struct hdlcdrv_channel_state {
        int ptt;
        int ptt;
        int dcd;
        int dcd;
        int ptt_keyed;
        int ptt_keyed;
        unsigned long tx_packets;
        unsigned long tx_packets;
        unsigned long tx_errors;
        unsigned long tx_errors;
        unsigned long rx_packets;
        unsigned long rx_packets;
        unsigned long rx_errors;
        unsigned long rx_errors;
};
};
 
 
struct hdlcdrv_ioctl {
struct hdlcdrv_ioctl {
        int cmd;
        int cmd;
        union {
        union {
                struct hdlcdrv_params mp;
                struct hdlcdrv_params mp;
                struct hdlcdrv_channel_params cp;
                struct hdlcdrv_channel_params cp;
                struct hdlcdrv_channel_state cs;
                struct hdlcdrv_channel_state cs;
                struct hdlcdrv_old_channel_state ocs;
                struct hdlcdrv_old_channel_state ocs;
                unsigned int calibrate;
                unsigned int calibrate;
                unsigned char bits;
                unsigned char bits;
                char modename[128];
                char modename[128];
                char drivername[32];
                char drivername[32];
        } data;
        } data;
};
};
 
 
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
 
 
/*
/*
 * ioctl values
 * ioctl values
 */
 */
#define HDLCDRVCTL_GETMODEMPAR       0
#define HDLCDRVCTL_GETMODEMPAR       0
#define HDLCDRVCTL_SETMODEMPAR       1
#define HDLCDRVCTL_SETMODEMPAR       1
#define HDLCDRVCTL_MODEMPARMASK      2  /* not handled by hdlcdrv */
#define HDLCDRVCTL_MODEMPARMASK      2  /* not handled by hdlcdrv */
#define HDLCDRVCTL_GETCHANNELPAR    10
#define HDLCDRVCTL_GETCHANNELPAR    10
#define HDLCDRVCTL_SETCHANNELPAR    11
#define HDLCDRVCTL_SETCHANNELPAR    11
#define HDLCDRVCTL_OLDGETSTAT       20
#define HDLCDRVCTL_OLDGETSTAT       20
#define HDLCDRVCTL_CALIBRATE        21
#define HDLCDRVCTL_CALIBRATE        21
#define HDLCDRVCTL_GETSTAT          22
#define HDLCDRVCTL_GETSTAT          22
 
 
/*
/*
 * these are mainly for debugging purposes
 * these are mainly for debugging purposes
 */
 */
#define HDLCDRVCTL_GETSAMPLES       30
#define HDLCDRVCTL_GETSAMPLES       30
#define HDLCDRVCTL_GETBITS          31
#define HDLCDRVCTL_GETBITS          31
 
 
/*
/*
 * not handled by hdlcdrv, but by its depending drivers
 * not handled by hdlcdrv, but by its depending drivers
 */
 */
#define HDLCDRVCTL_GETMODE          40
#define HDLCDRVCTL_GETMODE          40
#define HDLCDRVCTL_SETMODE          41
#define HDLCDRVCTL_SETMODE          41
#define HDLCDRVCTL_MODELIST         42
#define HDLCDRVCTL_MODELIST         42
#define HDLCDRVCTL_DRIVERNAME       43
#define HDLCDRVCTL_DRIVERNAME       43
 
 
/*
/*
 * mask of needed modem parameters, returned by HDLCDRVCTL_MODEMPARMASK
 * mask of needed modem parameters, returned by HDLCDRVCTL_MODEMPARMASK
 */
 */
#define HDLCDRV_PARMASK_IOBASE      (1<<0)
#define HDLCDRV_PARMASK_IOBASE      (1<<0)
#define HDLCDRV_PARMASK_IRQ         (1<<1)
#define HDLCDRV_PARMASK_IRQ         (1<<1)
#define HDLCDRV_PARMASK_DMA         (1<<2)
#define HDLCDRV_PARMASK_DMA         (1<<2)
#define HDLCDRV_PARMASK_DMA2        (1<<3)
#define HDLCDRV_PARMASK_DMA2        (1<<3)
#define HDLCDRV_PARMASK_SERIOBASE   (1<<4)
#define HDLCDRV_PARMASK_SERIOBASE   (1<<4)
#define HDLCDRV_PARMASK_PARIOBASE   (1<<5)
#define HDLCDRV_PARMASK_PARIOBASE   (1<<5)
#define HDLCDRV_PARMASK_MIDIIOBASE  (1<<6)
#define HDLCDRV_PARMASK_MIDIIOBASE  (1<<6)
 
 
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
 
 
#ifdef __KERNEL__
#ifdef __KERNEL__
 
 
#define HDLCDRV_MAGIC      0x5ac6e778
#define HDLCDRV_MAGIC      0x5ac6e778
#define HDLCDRV_IFNAMELEN    6
#define HDLCDRV_IFNAMELEN    6
#define HDLCDRV_HDLCBUFFER  32 /* should be a power of 2 for speed reasons */
#define HDLCDRV_HDLCBUFFER  32 /* should be a power of 2 for speed reasons */
#define HDLCDRV_BITBUFFER  256 /* should be a power of 2 for speed reasons */
#define HDLCDRV_BITBUFFER  256 /* should be a power of 2 for speed reasons */
#undef HDLCDRV_LOOPBACK  /* define for HDLC debugging purposes */
#undef HDLCDRV_LOOPBACK  /* define for HDLC debugging purposes */
#define HDLCDRV_DEBUG
#define HDLCDRV_DEBUG
 
 
/* maximum packet length, excluding CRC */
/* maximum packet length, excluding CRC */
#define HDLCDRV_MAXFLEN             400 
#define HDLCDRV_MAXFLEN             400 
 
 
 
 
struct hdlcdrv_hdlcbuffer {
struct hdlcdrv_hdlcbuffer {
        unsigned rd, wr;
        unsigned rd, wr;
        unsigned short buf[HDLCDRV_HDLCBUFFER];
        unsigned short buf[HDLCDRV_HDLCBUFFER];
};
};
 
 
#ifdef HDLCDRV_DEBUG
#ifdef HDLCDRV_DEBUG
struct hdlcdrv_bitbuffer {
struct hdlcdrv_bitbuffer {
        unsigned int rd;
        unsigned int rd;
        unsigned int wr;
        unsigned int wr;
        unsigned int shreg;
        unsigned int shreg;
        unsigned char buffer[HDLCDRV_BITBUFFER];
        unsigned char buffer[HDLCDRV_BITBUFFER];
};
};
 
 
extern inline void hdlcdrv_add_bitbuffer(struct hdlcdrv_bitbuffer *buf,
extern inline void hdlcdrv_add_bitbuffer(struct hdlcdrv_bitbuffer *buf,
                                         unsigned int bit)
                                         unsigned int bit)
{
{
        unsigned char new;
        unsigned char new;
 
 
        new = buf->shreg & 1;
        new = buf->shreg & 1;
        buf->shreg >>= 1;
        buf->shreg >>= 1;
        buf->shreg |= (!!bit) << 7;
        buf->shreg |= (!!bit) << 7;
        if (new) {
        if (new) {
                buf->buffer[buf->wr] = buf->shreg;
                buf->buffer[buf->wr] = buf->shreg;
                buf->wr = (buf->wr+1) % sizeof(buf->buffer);
                buf->wr = (buf->wr+1) % sizeof(buf->buffer);
                buf->shreg = 0x80;
                buf->shreg = 0x80;
        }
        }
}
}
 
 
extern inline void hdlcdrv_add_bitbuffer_word(struct hdlcdrv_bitbuffer *buf,
extern inline void hdlcdrv_add_bitbuffer_word(struct hdlcdrv_bitbuffer *buf,
                                              unsigned int bits)
                                              unsigned int bits)
{
{
        buf->buffer[buf->wr] = bits & 0xff;
        buf->buffer[buf->wr] = bits & 0xff;
        buf->wr = (buf->wr+1) % sizeof(buf->buffer);
        buf->wr = (buf->wr+1) % sizeof(buf->buffer);
        buf->buffer[buf->wr] = (bits >> 8) & 0xff;
        buf->buffer[buf->wr] = (bits >> 8) & 0xff;
        buf->wr = (buf->wr+1) % sizeof(buf->buffer);
        buf->wr = (buf->wr+1) % sizeof(buf->buffer);
 
 
}
}
#endif /* HDLCDRV_DEBUG */
#endif /* HDLCDRV_DEBUG */
 
 
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
/*
/*
 * Information that need to be kept for each driver.
 * Information that need to be kept for each driver.
 */
 */
 
 
struct hdlcdrv_ops {
struct hdlcdrv_ops {
        /*
        /*
         * first some informations needed by the hdlcdrv routines
         * first some informations needed by the hdlcdrv routines
         */
         */
        const char *drvname;
        const char *drvname;
        const char *drvinfo;
        const char *drvinfo;
        /*
        /*
         * the routines called by the hdlcdrv routines
         * the routines called by the hdlcdrv routines
         */
         */
        int (*open)(struct device *);
        int (*open)(struct device *);
        int (*close)(struct device *);
        int (*close)(struct device *);
        int (*ioctl)(struct device *, struct ifreq *,
        int (*ioctl)(struct device *, struct ifreq *,
                     struct hdlcdrv_ioctl *, int);
                     struct hdlcdrv_ioctl *, int);
};
};
 
 
struct hdlcdrv_state {
struct hdlcdrv_state {
        int magic;
        int magic;
 
 
        char ifname[HDLCDRV_IFNAMELEN];
        char ifname[HDLCDRV_IFNAMELEN];
 
 
        const struct hdlcdrv_ops *ops;
        const struct hdlcdrv_ops *ops;
 
 
        struct {
        struct {
                int bitrate;
                int bitrate;
        } par;
        } par;
 
 
        struct hdlcdrv_pttoutput {
        struct hdlcdrv_pttoutput {
                int dma2;
                int dma2;
                int seriobase;
                int seriobase;
                int pariobase;
                int pariobase;
                int midiiobase;
                int midiiobase;
                unsigned int flags;
                unsigned int flags;
        } ptt_out;
        } ptt_out;
 
 
        struct hdlcdrv_channel_params ch_params;
        struct hdlcdrv_channel_params ch_params;
 
 
        struct hdlcdrv_hdlcrx {
        struct hdlcdrv_hdlcrx {
                struct hdlcdrv_hdlcbuffer hbuf;
                struct hdlcdrv_hdlcbuffer hbuf;
                int in_hdlc_rx;
                int in_hdlc_rx;
                /* 0 = sync hunt, != 0 receiving */
                /* 0 = sync hunt, != 0 receiving */
                int rx_state;
                int rx_state;
                unsigned int bitstream;
                unsigned int bitstream;
                unsigned int bitbuf;
                unsigned int bitbuf;
                int numbits;
                int numbits;
                unsigned char dcd;
                unsigned char dcd;
 
 
                int len;
                int len;
                unsigned char *bp;
                unsigned char *bp;
                unsigned char buffer[HDLCDRV_MAXFLEN+2];
                unsigned char buffer[HDLCDRV_MAXFLEN+2];
        } hdlcrx;
        } hdlcrx;
 
 
        struct hdlcdrv_hdlctx {
        struct hdlcdrv_hdlctx {
                struct hdlcdrv_hdlcbuffer hbuf;
                struct hdlcdrv_hdlcbuffer hbuf;
                int in_hdlc_tx;
                int in_hdlc_tx;
                /*
                /*
                 * 0 = send flags
                 * 0 = send flags
                 * 1 = send txtail (flags)
                 * 1 = send txtail (flags)
                 * 2 = send packet
                 * 2 = send packet
                 */
                 */
                int tx_state;
                int tx_state;
                int numflags;
                int numflags;
                unsigned int bitstream;
                unsigned int bitstream;
                unsigned char ptt;
                unsigned char ptt;
                int calibrate;
                int calibrate;
                int slotcnt;
                int slotcnt;
 
 
                unsigned int bitbuf;
                unsigned int bitbuf;
                int numbits;
                int numbits;
 
 
                int len;
                int len;
                unsigned char *bp;
                unsigned char *bp;
                unsigned char buffer[HDLCDRV_MAXFLEN+2];
                unsigned char buffer[HDLCDRV_MAXFLEN+2];
        } hdlctx;
        } hdlctx;
 
 
#ifdef HDLCDRV_DEBUG
#ifdef HDLCDRV_DEBUG
        struct hdlcdrv_bitbuffer bitbuf_channel;
        struct hdlcdrv_bitbuffer bitbuf_channel;
        struct hdlcdrv_bitbuffer bitbuf_hdlc;
        struct hdlcdrv_bitbuffer bitbuf_hdlc;
#endif /* HDLCDRV_DEBUG */
#endif /* HDLCDRV_DEBUG */
 
 
#if LINUX_VERSION_CODE < 0x20119
#if LINUX_VERSION_CODE < 0x20119
        struct enet_statistics stats;
        struct enet_statistics stats;
#else
#else
        struct net_device_stats stats;
        struct net_device_stats stats;
#endif
#endif
        int ptt_keyed;
        int ptt_keyed;
 
 
        struct sk_buff_head send_queue;  /* Packets awaiting transmission */
        struct sk_buff_head send_queue;  /* Packets awaiting transmission */
};
};
 
 
 
 
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
 
 
extern inline int hdlcdrv_hbuf_full(struct hdlcdrv_hdlcbuffer *hb)
extern inline int hdlcdrv_hbuf_full(struct hdlcdrv_hdlcbuffer *hb)
{
{
        return !((HDLCDRV_HDLCBUFFER - 1 + hb->rd - hb->wr)
        return !((HDLCDRV_HDLCBUFFER - 1 + hb->rd - hb->wr)
                 % HDLCDRV_HDLCBUFFER);
                 % HDLCDRV_HDLCBUFFER);
}
}
 
 
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
 
 
extern inline int hdlcdrv_hbuf_empty(struct hdlcdrv_hdlcbuffer *hb)
extern inline int hdlcdrv_hbuf_empty(struct hdlcdrv_hdlcbuffer *hb)
{
{
        return hb->rd == hb->wr;
        return hb->rd == hb->wr;
}
}
 
 
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
 
 
extern inline unsigned short hdlcdrv_hbuf_get(struct hdlcdrv_hdlcbuffer *hb)
extern inline unsigned short hdlcdrv_hbuf_get(struct hdlcdrv_hdlcbuffer *hb)
{
{
        unsigned newr;
        unsigned newr;
        unsigned short val;
        unsigned short val;
        unsigned long flags;
        unsigned long flags;
 
 
        if (hb->rd == hb->wr)
        if (hb->rd == hb->wr)
                return 0;
                return 0;
        save_flags(flags);
        save_flags(flags);
        cli();
        cli();
        newr = (hb->rd+1) % HDLCDRV_HDLCBUFFER;
        newr = (hb->rd+1) % HDLCDRV_HDLCBUFFER;
        val = hb->buf[hb->rd];
        val = hb->buf[hb->rd];
        hb->rd = newr;
        hb->rd = newr;
        restore_flags(flags);
        restore_flags(flags);
        return val;
        return val;
}
}
 
 
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
 
 
extern inline void hdlcdrv_hbuf_put(struct hdlcdrv_hdlcbuffer *hb,
extern inline void hdlcdrv_hbuf_put(struct hdlcdrv_hdlcbuffer *hb,
                                    unsigned short val)
                                    unsigned short val)
{
{
        unsigned newp;
        unsigned newp;
        unsigned long flags;
        unsigned long flags;
 
 
        save_flags(flags);
        save_flags(flags);
        cli();
        cli();
        newp = (hb->wr+1) % HDLCDRV_HDLCBUFFER;
        newp = (hb->wr+1) % HDLCDRV_HDLCBUFFER;
        if (newp != hb->rd) {
        if (newp != hb->rd) {
                hb->buf[hb->wr] = val & 0xffff;
                hb->buf[hb->wr] = val & 0xffff;
                hb->wr = newp;
                hb->wr = newp;
        }
        }
        restore_flags(flags);
        restore_flags(flags);
}
}
 
 
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
 
 
extern inline void hdlcdrv_putbits(struct hdlcdrv_state *s, unsigned int bits)
extern inline void hdlcdrv_putbits(struct hdlcdrv_state *s, unsigned int bits)
{
{
        hdlcdrv_hbuf_put(&s->hdlcrx.hbuf, bits);
        hdlcdrv_hbuf_put(&s->hdlcrx.hbuf, bits);
}
}
 
 
extern inline unsigned int hdlcdrv_getbits(struct hdlcdrv_state *s)
extern inline unsigned int hdlcdrv_getbits(struct hdlcdrv_state *s)
{
{
        unsigned int ret;
        unsigned int ret;
 
 
        if (hdlcdrv_hbuf_empty(&s->hdlctx.hbuf)) {
        if (hdlcdrv_hbuf_empty(&s->hdlctx.hbuf)) {
                if (s->hdlctx.calibrate > 0)
                if (s->hdlctx.calibrate > 0)
                        s->hdlctx.calibrate--;
                        s->hdlctx.calibrate--;
                else
                else
                        s->hdlctx.ptt = 0;
                        s->hdlctx.ptt = 0;
                ret = 0;
                ret = 0;
        } else
        } else
                ret = hdlcdrv_hbuf_get(&s->hdlctx.hbuf);
                ret = hdlcdrv_hbuf_get(&s->hdlctx.hbuf);
#ifdef HDLCDRV_LOOPBACK
#ifdef HDLCDRV_LOOPBACK
        hdlcdrv_hbuf_put(&s->hdlcrx.hbuf, ret);
        hdlcdrv_hbuf_put(&s->hdlcrx.hbuf, ret);
#endif /* HDLCDRV_LOOPBACK */
#endif /* HDLCDRV_LOOPBACK */
        return ret;
        return ret;
}
}
 
 
extern inline void hdlcdrv_channelbit(struct hdlcdrv_state *s, unsigned int bit)
extern inline void hdlcdrv_channelbit(struct hdlcdrv_state *s, unsigned int bit)
{
{
#ifdef HDLCDRV_DEBUG
#ifdef HDLCDRV_DEBUG
        hdlcdrv_add_bitbuffer(&s->bitbuf_channel, bit);
        hdlcdrv_add_bitbuffer(&s->bitbuf_channel, bit);
#endif /* HDLCDRV_DEBUG */
#endif /* HDLCDRV_DEBUG */
}
}
 
 
extern inline void hdlcdrv_setdcd(struct hdlcdrv_state *s, int dcd)
extern inline void hdlcdrv_setdcd(struct hdlcdrv_state *s, int dcd)
{
{
        s->hdlcrx.dcd = !!dcd;
        s->hdlcrx.dcd = !!dcd;
}
}
 
 
extern inline int hdlcdrv_ptt(struct hdlcdrv_state *s)
extern inline int hdlcdrv_ptt(struct hdlcdrv_state *s)
{
{
        return s->hdlctx.ptt || (s->hdlctx.calibrate > 0);
        return s->hdlctx.ptt || (s->hdlctx.calibrate > 0);
}
}
 
 
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
 
 
void hdlcdrv_receiver(struct device *, struct hdlcdrv_state *);
void hdlcdrv_receiver(struct device *, struct hdlcdrv_state *);
void hdlcdrv_transmitter(struct device *, struct hdlcdrv_state *);
void hdlcdrv_transmitter(struct device *, struct hdlcdrv_state *);
void hdlcdrv_arbitrate(struct device *, struct hdlcdrv_state *);
void hdlcdrv_arbitrate(struct device *, struct hdlcdrv_state *);
int hdlcdrv_register_hdlcdrv(struct device *dev, const struct hdlcdrv_ops *ops,
int hdlcdrv_register_hdlcdrv(struct device *dev, const struct hdlcdrv_ops *ops,
                             unsigned int privsize, char *ifname,
                             unsigned int privsize, char *ifname,
                             unsigned int baseaddr, unsigned int irq,
                             unsigned int baseaddr, unsigned int irq,
                             unsigned int dma);
                             unsigned int dma);
int hdlcdrv_unregister_hdlcdrv(struct device *dev);
int hdlcdrv_unregister_hdlcdrv(struct device *dev);
 
 
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
 
 
 
 
 
 
#endif /* __KERNEL__ */
#endif /* __KERNEL__ */
 
 
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
 
 
#endif /* _HDLCDRV_H */
#endif /* _HDLCDRV_H */
 
 
/* -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- */
 
 

powered by: WebSVN 2.1.0

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