Merge git://oss.sgi.com:8090/xfs/xfs-2.6
[linux-drm-fsl-dcu.git] / net / atm / common.c
index 9e016f404e14342f1fb265c851d63818f2727479..282d761454baaca115b57ac3995dcb4466949fe5 100644 (file)
@@ -3,7 +3,6 @@
 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
 
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/kmod.h>
 #include <linux/net.h>         /* struct socket, struct proto_ops */
@@ -110,11 +109,11 @@ static inline int vcc_writable(struct sock *sk)
        struct atm_vcc *vcc = atm_sk(sk);
 
        return (vcc->qos.txtp.max_sdu +
-               atomic_read(&sk->sk_wmem_alloc)) <= sk->sk_sndbuf;
+               atomic_read(&sk->sk_wmem_alloc)) <= sk->sk_sndbuf;
 }
 
 static void vcc_write_space(struct sock *sk)
-{       
+{
        read_lock(&sk->sk_callback_lock);
 
        if (vcc_writable(sk)) {
@@ -132,7 +131,7 @@ static struct proto vcc_proto = {
        .owner    = THIS_MODULE,
        .obj_size = sizeof(struct atm_vcc),
 };
+
 int vcc_create(struct socket *sock, int protocol, int family)
 {
        struct sock *sk;
@@ -221,6 +220,29 @@ void vcc_release_async(struct atm_vcc *vcc, int reply)
 EXPORT_SYMBOL(vcc_release_async);
 
 
+void atm_dev_release_vccs(struct atm_dev *dev)
+{
+       int i;
+
+       write_lock_irq(&vcc_sklist_lock);
+       for (i = 0; i < VCC_HTABLE_SIZE; i++) {
+               struct hlist_head *head = &vcc_hash[i];
+               struct hlist_node *node, *tmp;
+               struct sock *s;
+               struct atm_vcc *vcc;
+
+               sk_for_each_safe(s, node, tmp, head) {
+                       vcc = atm_sk(s);
+                       if (vcc->dev == dev) {
+                               vcc_release_async(vcc, -EPIPE);
+                               sk_del_node_init(s);
+                       }
+               }
+       }
+       write_unlock_irq(&vcc_sklist_lock);
+}
+
+
 static int adjust_tp(struct atm_trafprm *tp,unsigned char aal)
 {
        int max_sdu;
@@ -332,12 +354,13 @@ static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi,
                return -EINVAL;
        if (vci > 0 && vci < ATM_NOT_RSV_VCI && !capable(CAP_NET_BIND_SERVICE))
                return -EPERM;
-       error = 0;
+       error = -ENODEV;
        if (!try_module_get(dev->ops->owner))
-               return -ENODEV;
+               return error;
        vcc->dev = dev;
        write_lock_irq(&vcc_sklist_lock);
-       if ((error = find_ci(vcc, &vpi, &vci))) {
+       if (test_bit(ATM_DF_REMOVED, &dev->flags) ||
+           (error = find_ci(vcc, &vpi, &vci))) {
                write_unlock_irq(&vcc_sklist_lock);
                goto fail_module_put;
        }
@@ -427,12 +450,12 @@ int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
                dev = try_then_request_module(atm_dev_lookup(itf), "atm-device-%d", itf);
        } else {
                dev = NULL;
-               down(&atm_dev_mutex);
+               mutex_lock(&atm_dev_mutex);
                if (!list_empty(&atm_devs)) {
                        dev = list_entry(atm_devs.next, struct atm_dev, dev_list);
                        atm_dev_hold(dev);
                }
-               up(&atm_dev_mutex);
+               mutex_unlock(&atm_dev_mutex);
        }
        if (!dev)
                return -ENODEV;
@@ -471,20 +494,20 @@ int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
        if (!skb)
                return error;
 
-       copied = skb->len; 
+       copied = skb->len;
        if (copied > size) {
-               copied = size; 
+               copied = size;
                msg->msg_flags |= MSG_TRUNC;
        }
 
-        error = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
-        if (error)
-                return error;
-        sock_recv_timestamp(msg, sk, skb);
-        DPRINTK("RcvM %d -= %d\n", atomic_read(&sk->rmem_alloc), skb->truesize);
-        atm_return(vcc, skb->truesize);
-        skb_free_datagram(sk, skb);
-        return copied;
+       error = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
+       if (error)
+               return error;
+       sock_recv_timestamp(msg, sk, skb);
+       DPRINTK("RcvM %d -= %d\n", atomic_read(&sk->rmem_alloc), skb->truesize);
+       atm_return(vcc, skb->truesize);
+       skb_free_datagram(sk, skb);
+       return copied;
 }
 
 
@@ -652,7 +675,7 @@ static int check_qos(struct atm_qos *qos)
        int error;
 
        if (!qos->txtp.traffic_class && !qos->rxtp.traffic_class)
-                return -EINVAL;
+               return -EINVAL;
        if (qos->txtp.traffic_class != qos->rxtp.traffic_class &&
            qos->txtp.traffic_class && qos->rxtp.traffic_class &&
            qos->txtp.traffic_class != ATM_ANYCLASS &&
@@ -763,12 +786,18 @@ static int __init atm_init(void)
                printk(KERN_ERR "atmsvc_init() failed with %d\n", error);
                goto out_atmpvc_exit;
        }
-        if ((error = atm_proc_init()) < 0) {
+       if ((error = atm_proc_init()) < 0) {
                printk(KERN_ERR "atm_proc_init() failed with %d\n",error);
                goto out_atmsvc_exit;
        }
+       if ((error = atm_sysfs_init()) < 0) {
+               printk(KERN_ERR "atm_sysfs_init() failed with %d\n",error);
+               goto out_atmproc_exit;
+       }
 out:
        return error;
+out_atmproc_exit:
+       atm_proc_exit();
 out_atmsvc_exit:
        atmsvc_exit();
 out_atmpvc_exit:
@@ -781,12 +810,14 @@ out_unregister_vcc_proto:
 static void __exit atm_exit(void)
 {
        atm_proc_exit();
+       atm_sysfs_exit();
        atmsvc_exit();
        atmpvc_exit();
        proto_unregister(&vcc_proto);
 }
 
-module_init(atm_init);
+subsys_initcall(atm_init);
+
 module_exit(atm_exit);
 
 MODULE_LICENSE("GPL");