diff options
author | markster <markster@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2004-07-28 13:35:55 +0000 |
---|---|---|
committer | markster <markster@5390a7c7-147a-4af0-8ec9-7488f05a26cb> | 2004-07-28 13:35:55 +0000 |
commit | d178c59876ebc7e620b8829f6d07c715fa64373b (patch) | |
tree | c499bed6671e21136d53530bdaf415a6b1d3588f /zaptel.c | |
parent | 12b723850e1c9a5519d1d8ca933a3e283a3f0eae (diff) |
Make data build on Linux 2.6
git-svn-id: http://svn.digium.com/svn/zaptel/trunk@443 5390a7c7-147a-4af0-8ec9-7488f05a26cb
Diffstat (limited to 'zaptel.c')
-rwxr-xr-x | zaptel.c | 93 |
1 files changed, 77 insertions, 16 deletions
@@ -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 @@ char *zt_lboname(int x) #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 @@ static void zt_net_close(hdlc_device *hdlc) } /* 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 @@ static void zt_net_close(hdlc_device *hdlc) /* 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 @@ static int zt_xmit(struct sk_buff *skb, struct net_device *dev) { /* 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 @@ static int zt_xmit(hdlc_device *hdlc, struct sk_buff *skb) 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 @@ static void zt_chan_unreg(struct zt_chan *chan) } #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 @@ static int zt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cmd 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 @@ static int zt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cmd 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 @@ static int zt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cmd 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 @@ static int zt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cmd 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 @@ out in the later versions, and is put back now. */ 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 @@ static inline void __zt_putbuf_chunk(struct zt_chan *ss, unsigned char *rxb) #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 @@ static inline void __zt_putbuf_chunk(struct zt_chan *ss, unsigned char *rxb) 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 @@ out in the later versions, and is put back now. */ #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 @@ out in the later versions, and is put back now. */ #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 |