[Asterisk-cvs] zaptel zaptel.c,1.87,1.88 zaptel.h,1.34,1.35
markster at lists.digium.com
markster at lists.digium.com
Wed Jul 28 09:49:57 CDT 2004
Update of /usr/cvsroot/zaptel
In directory localhost.localdomain:/tmp/cvs-serv18141
Modified Files:
zaptel.c zaptel.h
Log Message:
Make data build on Linux 2.6
Index: zaptel.c
===================================================================
RCS file: /usr/cvsroot/zaptel/zaptel.c,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -d -r1.87 -r1.88
--- zaptel.c 24 Jul 2004 16:03:27 -0000 1.87
+++ zaptel.c 28 Jul 2004 13:35:55 -0000 1.88
@@ -91,6 +91,12 @@
#endif
#define hdlc_to_ztchan(h) (((struct zt_hdlc *)(h))->chan)
+#define dev_to_ztchan(h) (((struct zt_hdlc *)(dev_to_hdlc(h)->priv))->chan)
+#ifdef LINUX26
+#define ztchan_to_dev(h) ((h)->hdlcnetdev->netdev)
+#else
+#define ztchan_to_dev(h) (&((h)->hdlcnetdev->netdev.netdev))
+#endif
/* macro-oni for determining a unit (channel) number */
#define UNIT(file) MINOR(file->f_dentry->d_inode->i_rdev)
@@ -1169,9 +1175,14 @@
#ifdef NEW_HDLC_INTERFACE
static int zt_net_open(struct net_device *dev)
{
+#ifdef LINUX26
+ int res = hdlc_open(dev);
+ struct zt_chan *ms = dev_to_ztchan(dev);
+#else
hdlc_device *hdlc = dev_to_hdlc(dev);
struct zt_chan *ms = hdlc_to_ztchan(hdlc);
- int res = hdlc_open(hdlc);
+ int res = hdlc_open(hdlc);
+#endif
/* if (!dev->hard_start_xmit) return res; is this really necessary? --byg */
if (res) /* this is necessary to avoid kernel panic when UNSPEC link encap, proven --byg */
@@ -1243,7 +1254,11 @@
}
/* Not much to do here. Just deallocate the buffers */
zt_reallocbufs(ms, 0, 0);
+#ifdef LINUX26
+ hdlc_close(dev);
+#else
hdlc_close(hdlc);
+#endif
#ifndef LINUX26
MOD_DEC_USE_COUNT;
#endif
@@ -1258,8 +1273,13 @@
/* kernel 2.4.20+ has introduced attach function, dunno what to do,
just copy sources from dscc4 to be sure and ready for further mastering,
NOOP right now (i.e. really a stub) --byg */
+#ifdef LINUX26
+static int zt_net_attach(struct net_device *dev, unsigned short encoding,
+ unsigned short parity)
+#else
static int zt_net_attach(hdlc_device *hdlc, unsigned short encoding,
unsigned short parity)
+#endif
{
/* struct net_device *dev = hdlc_to_dev(hdlc);
struct dscc4_dev_priv *dpriv = dscc4_priv(dev);
@@ -1299,23 +1319,31 @@
{
/* FIXME: this construction seems to be not very optimal for me but I could find nothing better at the moment (Friday, 10PM :( ) --byg */
/* struct zt_chan *ss = hdlc_to_ztchan(list_entry(dev, struct zt_hdlc, netdev.netdev));*/
+#ifdef LINUX26
+ struct zt_chan *ss = dev_to_ztchan(dev);
+ struct net_device_stats *stats = hdlc_stats(dev);
+#else
struct zt_chan *ss = (list_entry(dev, struct zt_hdlc, netdev.netdev)->chan);
+ struct net_device_stats *stats = &ss->hdlcnetdev->netdev.stats;
+#endif
+
#else
static int zt_xmit(hdlc_device *hdlc, struct sk_buff *skb)
{
struct zt_chan *ss = hdlc_to_ztchan(hdlc);
struct net_device *dev = &ss->hdlcnetdev->netdev.netdev;
+ struct net_device_stats *stats = &ss->hdlcnetdev->netdev.stats;
#endif
int retval = 1;
int x,oldbuf;
unsigned int fcs;
unsigned char *data;
- long flags;
+ unsigned long flags;
/* See if we have any buffers */
spin_lock_irqsave(&ss->lock, flags);
if (skb->len > ss->blocksize - 2) {
printk(KERN_ERR "zt_xmit(%s): skb is too large (%d > %d)\n", dev->name, skb->len, ss->blocksize -2);
- ss->hdlcnetdev->netdev.stats.tx_dropped++;
+ stats->tx_dropped++;
retval = 0;
} else if (ss->inwritebuf >= 0) {
/* We have a place to put this packet */
@@ -1347,8 +1375,8 @@
ss->outwritebuf = oldbuf;
}
dev->trans_start = jiffies;
- ss->hdlcnetdev->netdev.stats.tx_packets++;
- ss->hdlcnetdev->netdev.stats.tx_bytes += ss->writen[oldbuf];
+ stats->tx_packets++;
+ stats->tx_bytes += ss->writen[oldbuf];
#if CONFIG_ZAPATA_DEBUG
printk("Buffered %d bytes to go out in buffer %d\n", ss->writen[oldbuf], oldbuf);
for (x=0;x<ss->writen[oldbuf];x++)
@@ -1492,7 +1520,12 @@
}
#ifdef CONFIG_ZAPATA_NET
if (chan->flags & ZT_FLAG_NETDEV) {
+#ifdef LINUX26
+ unregister_hdlc_device(chan->hdlcnetdev->netdev);
+ free_netdev(chan->hdlcnetdev->netdev);
+#else
unregister_hdlc_device(&chan->hdlcnetdev->netdev);
+#endif
kfree(chan->hdlcnetdev);
chan->hdlcnetdev = NULL;
}
@@ -2912,7 +2945,6 @@
struct zt_maintinfo maint;
unsigned long flags;
int rv;
-
switch(cmd) {
case ZT_SPANCONFIG:
if (copy_from_user(&lc, (struct zt_lineconfig *)data, sizeof(lc)))
@@ -2972,12 +3004,17 @@
spin_lock_irqsave(&chans[ch.chan]->lock, flags);
#ifdef CONFIG_ZAPATA_NET
if (chans[ch.chan]->flags & ZT_FLAG_NETDEV) {
- if (chans[ch.chan]->hdlcnetdev->netdev.netdev.flags & IFF_UP) {
+ if (ztchan_to_dev(chans[ch.chan])->flags & IFF_UP) {
spin_unlock_irqrestore(&chans[ch.chan]->lock, flags);
printk(KERN_WARNING "Can't switch HDLC net mode on channel %s, since current interface is up\n", chans[ch.chan]->name);
return -EBUSY;
}
+#ifdef LINUX26
+ unregister_hdlc_device(chans[ch.chan]->hdlcnetdev->netdev);
+ free_netdev(chans[ch.chan]->hdlcnetdev->netdev);
+#else
unregister_hdlc_device(&chans[ch.chan]->hdlcnetdev->netdev);
+#endif
kfree(chans[ch.chan]->hdlcnetdev);
chans[ch.chan]->hdlcnetdev = NULL;
chans[ch.chan]->flags &= ~ZT_FLAG_NETDEV;
@@ -3053,6 +3090,24 @@
if (chans[ch.chan]->hdlcnetdev) {
/* struct hdlc_device *hdlc = chans[ch.chan]->hdlcnetdev;
struct net_device *d = hdlc_to_dev(hdlc); mmm...get it right later --byg */
+#ifdef LINUX26
+ chans[ch.chan]->hdlcnetdev->netdev = alloc_hdlcdev(chans[ch.chan]->hdlcnetdev);
+ if (chans[ch.chan]->hdlcnetdev->netdev) {
+ chans[ch.chan]->hdlcnetdev->chan = chans[ch.chan];
+ SET_MODULE_OWNER(chans[ch.chan]->hdlcnetdev->netdev);
+ chans[ch.chan]->hdlcnetdev->netdev->irq = chans[ch.chan]->span->irq;
+ chans[ch.chan]->hdlcnetdev->netdev->tx_queue_len = 50;
+ chans[ch.chan]->hdlcnetdev->netdev->do_ioctl = zt_net_ioctl;
+ chans[ch.chan]->hdlcnetdev->netdev->open = zt_net_open;
+ chans[ch.chan]->hdlcnetdev->netdev->stop = zt_net_stop;
+ dev_to_hdlc(chans[ch.chan]->hdlcnetdev->netdev)->attach = zt_net_attach;
+ dev_to_hdlc(chans[ch.chan]->hdlcnetdev->netdev)->xmit = zt_xmit;
+ res = register_hdlc_device(chans[ch.chan]->hdlcnetdev->netdev);
+ } else {
+ printk("Unable to allocate hdlc: *shrug*\n");
+ res = -1;
+ }
+#else /* LINUX26 */
chans[ch.chan]->hdlcnetdev->chan = chans[ch.chan];
#ifndef HDLC_MAINTAINERS_ARE_MORE_STUPID_THAN_I_THOUGHT
chans[ch.chan]->hdlcnetdev->netdev.ioctl = zt_net_ioctl;
@@ -3072,6 +3127,7 @@
chans[ch.chan]->hdlcnetdev->netdev.netdev.irq = chans[ch.chan]->span->irq;
chans[ch.chan]->hdlcnetdev->netdev.netdev.tx_queue_len = 50;
res = register_hdlc_device(&chans[ch.chan]->hdlcnetdev->netdev);
+#endif /* LINUX26 */
if (!res)
chans[ch.chan]->flags |= ZT_FLAG_NETDEV;
} else {
@@ -4686,7 +4742,7 @@
fasthdlc_tx_frame_nocheck(&ms->txhdlc);
#ifdef CONFIG_ZAPATA_NET
if (ms->flags & ZT_FLAG_NETDEV)
- netif_wake_queue(&ms->hdlcnetdev->netdev.netdev);
+ netif_wake_queue(ztchan_to_dev(ms));
#endif
#ifdef CONFIG_ZAPATA_PPP
if (ms->flags & ZT_FLAG_PPP) {
@@ -5359,6 +5415,11 @@
#if defined(CONFIG_ZAPATA_NET) || defined(CONFIG_ZAPATA_PPP)
/* SKB for receiving network stuff */
struct sk_buff *skb=NULL;
+#ifdef LINUX26
+ struct net_device_stats *stats = hdlc_stats(ms->hdlcnetdev->netdev);
+#else
+ struct net_device_stats *stats = &ms->hdlcnetdev->netdev.stats;
+#endif
#endif
int oldbuf;
int eof=0;
@@ -5460,14 +5521,14 @@
memcpy(skb->data, ms->readbuf[ms->inreadbuf], ms->readn[ms->inreadbuf]);
skb_put(skb, ms->readn[ms->inreadbuf]);
#ifdef CONFIG_ZAPATA_NET
- ms->hdlcnetdev->netdev.stats.rx_packets++;
- ms->hdlcnetdev->netdev.stats.rx_bytes += ms->readn[ms->inreadbuf];
+ stats->rx_packets++;
+ stats->rx_bytes += ms->readn[ms->inreadbuf];
#endif
} else {
#ifdef CONFIG_ZAPATA_NET
if (ms->flags & ZT_FLAG_NETDEV)
- ms->hdlcnetdev->netdev.stats.rx_dropped++;
+ stats->rx_dropped++;
#endif
#ifdef CONFIG_ZAPATA_PPP
if (ms->flags & ZT_FLAG_PPP) {
@@ -5534,13 +5595,13 @@
#ifdef CONFIG_ZAPATA_NET
if (ms->flags & ZT_FLAG_NETDEV) {
- ms->hdlcnetdev->netdev.stats.rx_errors++;
+ stats->rx_errors++;
if (abort == ZT_EVENT_OVERRUN)
- ms->hdlcnetdev->netdev.stats.rx_over_errors++;
+ stats->rx_over_errors++;
if (abort == ZT_EVENT_BADFCS)
- ms->hdlcnetdev->netdev.stats.rx_crc_errors++;
+ stats->rx_crc_errors++;
if (abort == ZT_EVENT_ABORT)
- ms->hdlcnetdev->netdev.stats.rx_frame_errors++;
+ stats->rx_frame_errors++;
} else
#endif
#ifdef CONFIG_ZAPATA_PPP
@@ -5565,7 +5626,7 @@
#ifdef NEW_HDLC_INTERFACE
{
skb->mac.raw = skb->data;
- skb->dev = &ms->hdlcnetdev->netdev.netdev;
+ skb->dev = ztchan_to_dev(ms);
#ifdef ZAP_HDLC_TYPE_TRANS
skb->protocol = hdlc_type_trans(skb, &ms->hdlcnetdev->netdev.netdev);
#else
Index: zaptel.h
===================================================================
RCS file: /usr/cvsroot/zaptel/zaptel.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- zaptel.h 30 Jun 2004 14:08:42 -0000 1.34
+++ zaptel.h 28 Jul 2004 13:35:55 -0000 1.35
@@ -44,6 +44,10 @@
#endif
#include <linux/fs.h>
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
+#define LINUX26
+#endif
+
#include "ecdis.h"
#include "fasthdlc.h"
#endif
@@ -878,7 +882,11 @@
#ifdef CONFIG_ZAPATA_NET
struct zt_hdlc {
+#ifdef LINUX26
+ struct net_device *netdev;
+#else
hdlc_device netdev;
+#endif
struct zt_chan *chan;
};
#endif
@@ -1415,10 +1423,6 @@
#endif /* CONFIG_CALC_XLAW */
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
-#define LINUX26
-#endif
-
#endif /* __KERNEL__ */
#endif /* _LINUX_ZAPTEL_H */
More information about the svn-commits
mailing list