]> err.no Git - linux-2.6/blobdiff - drivers/net/wan/cosa.c
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
[linux-2.6] / drivers / net / wan / cosa.c
index 26058b4f8f36b2c5785a9291fd4baf8af10e017d..5827324e9d9f94a2abde26a450c1b4be90c941cf 100644 (file)
@@ -90,7 +90,9 @@
 #include <linux/ioport.h>
 #include <linux/netdevice.h>
 #include <linux/spinlock.h>
+#include <linux/mutex.h>
 #include <linux/device.h>
+#include <linux/smp_lock.h>
 
 #undef COSA_SLOW_IO    /* for testing purposes only */
 
@@ -127,7 +129,8 @@ struct channel_data {
        int (*tx_done)(struct channel_data *channel, int size);
 
        /* Character device parts */
-       struct semaphore rsem, wsem;
+       struct mutex rlock;
+       struct semaphore wsem;
        char *rxdata;
        int rxsize;
        wait_queue_head_t txwaitq, rxwaitq;
@@ -154,8 +157,8 @@ struct cosa_data {
        int nchannels;                  /* # of channels on this card */
        int driver_status;              /* For communicating with firmware */
        int firmware_status;            /* Downloaded, reseted, etc. */
-       long int rxbitmap, txbitmap;    /* Bitmap of channels who are willing to send/receive data */
-       long int rxtx;                  /* RX or TX in progress? */
+       unsigned long rxbitmap, txbitmap;/* Bitmap of channels who are willing to send/receive data */
+       unsigned long rxtx;             /* RX or TX in progress? */
        int enabled;
        int usage;                              /* usage count */
        int txchan, txsize, rxsize;
@@ -395,8 +398,7 @@ static int __init cosa_init(void)
                goto out_chrdev;
        }
        for (i=0; i<nr_cards; i++) {
-               class_device_create(cosa_class, NULL, MKDEV(cosa_major, i),
-                               NULL, "cosa%d", i);
+               device_create(cosa_class, NULL, MKDEV(cosa_major, i), "cosa%d", i);
        }
        err = 0;
        goto out;
@@ -415,7 +417,7 @@ static void __exit cosa_exit(void)
        printk(KERN_INFO "Unloading the cosa module\n");
 
        for (i=0; i<nr_cards; i++)
-               class_device_destroy(cosa_class, MKDEV(cosa_major, i));
+               device_destroy(cosa_class, MKDEV(cosa_major, i));
        class_destroy(cosa_class);
        for (cosa=cosa_cards; nr_cards--; cosa++) {
                /* Clean up the per-channel data */
@@ -628,7 +630,7 @@ static void sppp_channel_init(struct channel_data *chan)
        d->base_addr = chan->cosa->datareg;
        d->irq = chan->cosa->irq;
        d->dma = chan->cosa->dma;
-       d->priv = chan;
+       d->ml_priv = chan;
        sppp_attach(&chan->pppdev);
        if (register_netdev(d)) {
                printk(KERN_WARNING "%s: register_netdev failed.\n", d->name);
@@ -649,7 +651,7 @@ static void sppp_channel_delete(struct channel_data *chan)
 
 static int cosa_sppp_open(struct net_device *d)
 {
-       struct channel_data *chan = d->priv;
+       struct channel_data *chan = d->ml_priv;
        int err;
        unsigned long flags;
 
@@ -689,7 +691,7 @@ static int cosa_sppp_open(struct net_device *d)
 
 static int cosa_sppp_tx(struct sk_buff *skb, struct net_device *dev)
 {
-       struct channel_data *chan = dev->priv;
+       struct channel_data *chan = dev->ml_priv;
 
        netif_stop_queue(dev);
 
@@ -700,7 +702,7 @@ static int cosa_sppp_tx(struct sk_buff *skb, struct net_device *dev)
 
 static void cosa_sppp_timeout(struct net_device *dev)
 {
-       struct channel_data *chan = dev->priv;
+       struct channel_data *chan = dev->ml_priv;
 
        if (test_bit(RXBIT, &chan->cosa->rxtx)) {
                chan->stats.rx_errors++;
@@ -719,7 +721,7 @@ static void cosa_sppp_timeout(struct net_device *dev)
 
 static int cosa_sppp_close(struct net_device *d)
 {
-       struct channel_data *chan = d->priv;
+       struct channel_data *chan = d->ml_priv;
        unsigned long flags;
 
        netif_stop_queue(d);
@@ -799,7 +801,7 @@ static int sppp_tx_done(struct channel_data *chan, int size)
 
 static struct net_device_stats *cosa_net_stats(struct net_device *dev)
 {
-       struct channel_data *chan = dev->priv;
+       struct channel_data *chan = dev->ml_priv;
        return &chan->stats;
 }
 
@@ -808,7 +810,7 @@ static struct net_device_stats *cosa_net_stats(struct net_device *dev)
 
 static void chardev_channel_init(struct channel_data *chan)
 {
-       init_MUTEX(&chan->rsem);
+       mutex_init(&chan->rlock);
        init_MUTEX(&chan->wsem);
 }
 
@@ -826,12 +828,12 @@ static ssize_t cosa_read(struct file *file,
                        cosa->name, cosa->firmware_status);
                return -EPERM;
        }
-       if (down_interruptible(&chan->rsem))
+       if (mutex_lock_interruptible(&chan->rlock))
                return -ERESTARTSYS;
        
        if ((chan->rxdata = kmalloc(COSA_MTU, GFP_DMA|GFP_KERNEL)) == NULL) {
                printk(KERN_INFO "%s: cosa_read() - OOM\n", cosa->name);
-               up(&chan->rsem);
+               mutex_unlock(&chan->rlock);
                return -ENOMEM;
        }
 
@@ -849,7 +851,7 @@ static ssize_t cosa_read(struct file *file,
                        remove_wait_queue(&chan->rxwaitq, &wait);
                        current->state = TASK_RUNNING;
                        spin_unlock_irqrestore(&cosa->lock, flags);
-                       up(&chan->rsem);
+                       mutex_unlock(&chan->rlock);
                        return -ERESTARTSYS;
                }
        }
@@ -858,7 +860,7 @@ static ssize_t cosa_read(struct file *file,
        kbuf = chan->rxdata;
        count = chan->rxsize;
        spin_unlock_irqrestore(&cosa->lock, flags);
-       up(&chan->rsem);
+       mutex_unlock(&chan->rlock);
 
        if (copy_to_user(buf, kbuf, count)) {
                kfree(kbuf);
@@ -969,15 +971,21 @@ static int cosa_open(struct inode *inode, struct file *file)
        struct channel_data *chan;
        unsigned long flags;
        int n;
+       int ret = 0;
 
+       lock_kernel();
        if ((n=iminor(file->f_path.dentry->d_inode)>>CARD_MINOR_BITS)
-               >= nr_cards)
-               return -ENODEV;
+               >= nr_cards) {
+               ret = -ENODEV;
+               goto out;
+       }
        cosa = cosa_cards+n;
 
        if ((n=iminor(file->f_path.dentry->d_inode)
-               & ((1<<CARD_MINOR_BITS)-1)) >= cosa->nchannels)
-               return -ENODEV;
+               & ((1<<CARD_MINOR_BITS)-1)) >= cosa->nchannels) {
+               ret = -ENODEV;
+               goto out;
+       }
        chan = cosa->chan + n;
        
        file->private_data = chan;
@@ -986,7 +994,8 @@ static int cosa_open(struct inode *inode, struct file *file)
 
        if (chan->usage < 0) { /* in netdev mode */
                spin_unlock_irqrestore(&cosa->lock, flags);
-               return -EBUSY;
+               ret = -EBUSY;
+               goto out;
        }
        cosa->usage++;
        chan->usage++;
@@ -995,7 +1004,9 @@ static int cosa_open(struct inode *inode, struct file *file)
        chan->setup_rx = chrdev_setup_rx;
        chan->rx_done = chrdev_rx_done;
        spin_unlock_irqrestore(&cosa->lock, flags);
-       return 0;
+out:
+       unlock_kernel();
+       return ret;
 }
 
 static int cosa_release(struct inode *inode, struct file *file)
@@ -1216,7 +1227,7 @@ static int cosa_sppp_ioctl(struct net_device *dev, struct ifreq *ifr,
        int cmd)
 {
        int rv;
-       struct channel_data *chan = dev->priv;
+       struct channel_data *chan = dev->ml_priv;
        rv = cosa_ioctl_common(chan->cosa, chan, cmd, (unsigned long)ifr->ifr_data);
        if (rv == -ENOIOCTLCMD) {
                return sppp_do_ioctl(dev, ifr, cmd);