nfsd4: shut down callback queue outside state lock
[safe/jmp/linux-2.6] / net / bluetooth / hci_sysfs.c
index b7c5108..0e8e1a5 100644 (file)
@@ -1,15 +1,20 @@
 /* Bluetooth HCI driver model support. */
 
 #include <linux/kernel.h>
+#include <linux/slab.h>
 #include <linux/init.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>
 
 #include <net/bluetooth/bluetooth.h>
 #include <net/bluetooth/hci_core.h>
 
-struct class *bt_class = NULL;
-EXPORT_SYMBOL_GPL(bt_class);
+static struct class *bt_class;
 
-static struct workqueue_struct *bluetooth;
+struct dentry *bt_debugfs = NULL;
+EXPORT_SYMBOL_GPL(bt_debugfs);
+
+static struct workqueue_struct *bt_workq;
 
 static inline char *link_typetostr(int type)
 {
@@ -68,7 +73,7 @@ static struct attribute_group bt_link_group = {
        .attrs = bt_link_attrs,
 };
 
-static struct attribute_group *bt_link_groups[] = {
+static const struct attribute_group *bt_link_groups[] = {
        &bt_link_group,
        NULL
 };
@@ -88,35 +93,18 @@ static struct device_type bt_link = {
 static void add_conn(struct work_struct *work)
 {
        struct hci_conn *conn = container_of(work, struct hci_conn, work_add);
-
-       /* ensure previous add/del is complete */
-       flush_workqueue(bluetooth);
-
-       if (device_add(&conn->dev) < 0) {
-               BT_ERR("Failed to register connection device");
-               return;
-       }
-}
-
-void hci_conn_add_sysfs(struct hci_conn *conn)
-{
        struct hci_dev *hdev = conn->hdev;
 
-       BT_DBG("conn %p", conn);
-
-       conn->dev.type = &bt_link;
-       conn->dev.class = bt_class;
-       conn->dev.parent = &hdev->dev;
-
        dev_set_name(&conn->dev, "%s:%d", hdev->name, conn->handle);
 
        dev_set_drvdata(&conn->dev, conn);
 
-       device_initialize(&conn->dev);
-
-       INIT_WORK(&conn->work_add, add_conn);
+       if (device_add(&conn->dev) < 0) {
+               BT_ERR("Failed to register connection device");
+               return;
+       }
 
-       queue_work(bluetooth, &conn->work_add);
+       hci_dev_hold(hdev);
 }
 
 /*
@@ -134,8 +122,8 @@ static void del_conn(struct work_struct *work)
        struct hci_conn *conn = container_of(work, struct hci_conn, work_del);
        struct hci_dev *hdev = conn->hdev;
 
-       /* ensure previous add/del is complete */
-       flush_workqueue(bluetooth);
+       if (!device_is_registered(&conn->dev))
+               return;
 
        while (1) {
                struct device *dev;
@@ -149,24 +137,43 @@ static void del_conn(struct work_struct *work)
 
        device_del(&conn->dev);
        put_device(&conn->dev);
+
        hci_dev_put(hdev);
 }
 
-void hci_conn_del_sysfs(struct hci_conn *conn)
+void hci_conn_init_sysfs(struct hci_conn *conn)
 {
+       struct hci_dev *hdev = conn->hdev;
+
        BT_DBG("conn %p", conn);
 
-       if (!device_is_registered(&conn->dev))
-               return;
+       conn->dev.type = &bt_link;
+       conn->dev.class = bt_class;
+       conn->dev.parent = &hdev->dev;
 
+       device_initialize(&conn->dev);
+
+       INIT_WORK(&conn->work_add, add_conn);
        INIT_WORK(&conn->work_del, del_conn);
+}
 
-       queue_work(bluetooth, &conn->work_del);
+void hci_conn_add_sysfs(struct hci_conn *conn)
+{
+       BT_DBG("conn %p", conn);
+
+       queue_work(bt_workq, &conn->work_add);
 }
 
-static inline char *host_typetostr(int type)
+void hci_conn_del_sysfs(struct hci_conn *conn)
 {
-       switch (type) {
+       BT_DBG("conn %p", conn);
+
+       queue_work(bt_workq, &conn->work_del);
+}
+
+static inline char *host_bustostr(int bus)
+{
+       switch (bus) {
        case HCI_VIRTUAL:
                return "VIRTUAL";
        case HCI_USB:
@@ -186,10 +193,28 @@ static inline char *host_typetostr(int type)
        }
 }
 
+static inline char *host_typetostr(int type)
+{
+       switch (type) {
+       case HCI_BREDR:
+               return "BR/EDR";
+       case HCI_80211:
+               return "802.11";
+       default:
+               return "UNKNOWN";
+       }
+}
+
+static ssize_t show_bus(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct hci_dev *hdev = dev_get_drvdata(dev);
+       return sprintf(buf, "%s\n", host_bustostr(hdev->bus));
+}
+
 static ssize_t show_type(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct hci_dev *hdev = dev_get_drvdata(dev);
-       return sprintf(buf, "%s\n", host_typetostr(hdev->type));
+       return sprintf(buf, "%s\n", host_typetostr(hdev->dev_type));
 }
 
 static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf)
@@ -249,32 +274,6 @@ static ssize_t show_hci_revision(struct device *dev, struct device_attribute *at
        return sprintf(buf, "%d\n", hdev->hci_rev);
 }
 
-static ssize_t show_inquiry_cache(struct device *dev, struct device_attribute *attr, char *buf)
-{
-       struct hci_dev *hdev = dev_get_drvdata(dev);
-       struct inquiry_cache *cache = &hdev->inq_cache;
-       struct inquiry_entry *e;
-       int n = 0;
-
-       hci_dev_lock_bh(hdev);
-
-       for (e = cache->list; e; e = e->next) {
-               struct inquiry_data *data = &e->data;
-               bdaddr_t bdaddr;
-               baswap(&bdaddr, &data->bdaddr);
-               n += sprintf(buf + n, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
-                               batostr(&bdaddr),
-                               data->pscan_rep_mode, data->pscan_period_mode,
-                               data->pscan_mode, data->dev_class[2],
-                               data->dev_class[1], data->dev_class[0],
-                               __le16_to_cpu(data->clock_offset),
-                               data->rssi, data->ssp_mode, e->timestamp);
-       }
-
-       hci_dev_unlock_bh(hdev);
-       return n;
-}
-
 static ssize_t show_idle_timeout(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct hci_dev *hdev = dev_get_drvdata(dev);
@@ -353,6 +352,7 @@ static ssize_t store_sniff_min_interval(struct device *dev, struct device_attrib
        return count;
 }
 
+static DEVICE_ATTR(bus, S_IRUGO, show_bus, NULL);
 static DEVICE_ATTR(type, S_IRUGO, show_type, NULL);
 static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
 static DEVICE_ATTR(class, S_IRUGO, show_class, NULL);
@@ -361,7 +361,6 @@ static DEVICE_ATTR(features, S_IRUGO, show_features, NULL);
 static DEVICE_ATTR(manufacturer, S_IRUGO, show_manufacturer, NULL);
 static DEVICE_ATTR(hci_version, S_IRUGO, show_hci_version, NULL);
 static DEVICE_ATTR(hci_revision, S_IRUGO, show_hci_revision, NULL);
-static DEVICE_ATTR(inquiry_cache, S_IRUGO, show_inquiry_cache, NULL);
 
 static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR,
                                show_idle_timeout, store_idle_timeout);
@@ -371,6 +370,7 @@ static DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR,
                                show_sniff_min_interval, store_sniff_min_interval);
 
 static struct attribute *bt_host_attrs[] = {
+       &dev_attr_bus.attr,
        &dev_attr_type.attr,
        &dev_attr_name.attr,
        &dev_attr_class.attr,
@@ -379,7 +379,6 @@ static struct attribute *bt_host_attrs[] = {
        &dev_attr_manufacturer.attr,
        &dev_attr_hci_version.attr,
        &dev_attr_hci_revision.attr,
-       &dev_attr_inquiry_cache.attr,
        &dev_attr_idle_timeout.attr,
        &dev_attr_sniff_max_interval.attr,
        &dev_attr_sniff_min_interval.attr,
@@ -390,7 +389,7 @@ static struct attribute_group bt_host_group = {
        .attrs = bt_host_attrs,
 };
 
-static struct attribute_group *bt_host_groups[] = {
+static const struct attribute_group *bt_host_groups[] = {
        &bt_host_group,
        NULL
 };
@@ -407,12 +406,50 @@ static struct device_type bt_host = {
        .release = bt_host_release,
 };
 
+static int inquiry_cache_show(struct seq_file *f, void *p)
+{
+       struct hci_dev *hdev = f->private;
+       struct inquiry_cache *cache = &hdev->inq_cache;
+       struct inquiry_entry *e;
+
+       hci_dev_lock_bh(hdev);
+
+       for (e = cache->list; e; e = e->next) {
+               struct inquiry_data *data = &e->data;
+               bdaddr_t bdaddr;
+               baswap(&bdaddr, &data->bdaddr);
+               seq_printf(f, "%s %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n",
+                          batostr(&bdaddr),
+                          data->pscan_rep_mode, data->pscan_period_mode,
+                          data->pscan_mode, data->dev_class[2],
+                          data->dev_class[1], data->dev_class[0],
+                          __le16_to_cpu(data->clock_offset),
+                          data->rssi, data->ssp_mode, e->timestamp);
+       }
+
+       hci_dev_unlock_bh(hdev);
+
+       return 0;
+}
+
+static int inquiry_cache_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, inquiry_cache_show, inode->i_private);
+}
+
+static const struct file_operations inquiry_cache_fops = {
+       .open           = inquiry_cache_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
 int hci_register_sysfs(struct hci_dev *hdev)
 {
        struct device *dev = &hdev->dev;
        int err;
 
-       BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
+       BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);
 
        dev->type = &bt_host;
        dev->class = bt_class;
@@ -426,25 +463,39 @@ int hci_register_sysfs(struct hci_dev *hdev)
        if (err < 0)
                return err;
 
+       if (!bt_debugfs)
+               return 0;
+
+       hdev->debugfs = debugfs_create_dir(hdev->name, bt_debugfs);
+       if (!hdev->debugfs)
+               return 0;
+
+       debugfs_create_file("inquiry_cache", 0444, hdev->debugfs,
+                                               hdev, &inquiry_cache_fops);
+
        return 0;
 }
 
 void hci_unregister_sysfs(struct hci_dev *hdev)
 {
-       BT_DBG("%p name %s type %d", hdev, hdev->name, hdev->type);
+       BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);
+
+       debugfs_remove_recursive(hdev->debugfs);
 
        device_del(&hdev->dev);
 }
 
 int __init bt_sysfs_init(void)
 {
-       bluetooth = create_singlethread_workqueue("bluetooth");
-       if (!bluetooth)
+       bt_workq = create_singlethread_workqueue("bluetooth");
+       if (!bt_workq)
                return -ENOMEM;
 
+       bt_debugfs = debugfs_create_dir("bluetooth", NULL);
+
        bt_class = class_create(THIS_MODULE, "bluetooth");
        if (IS_ERR(bt_class)) {
-               destroy_workqueue(bluetooth);
+               destroy_workqueue(bt_workq);
                return PTR_ERR(bt_class);
        }
 
@@ -453,7 +504,9 @@ int __init bt_sysfs_init(void)
 
 void bt_sysfs_cleanup(void)
 {
-       destroy_workqueue(bluetooth);
-
        class_destroy(bt_class);
+
+       debugfs_remove_recursive(bt_debugfs);
+
+       destroy_workqueue(bt_workq);
 }