ieee1394: merge from Linus
[powerpc.git] / drivers / ieee1394 / hosts.c
index aeeaeb6..59e6f49 100644 (file)
@@ -10,7 +10,6 @@
  * directory of the kernel sources for details.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/list.h>
@@ -19,6 +18,7 @@
 #include <linux/pci.h>
 #include <linux/timer.h>
 #include <linux/jiffies.h>
+#include <linux/mutex.h>
 
 #include "csr1212.h"
 #include "ieee1394.h"
@@ -61,12 +61,12 @@ static void delayed_reset_bus(void * __reset_info)
 
 static int dummy_transmit_packet(struct hpsb_host *h, struct hpsb_packet *p)
 {
-        return 0;
+       return 0;
 }
 
 static int dummy_devctl(struct hpsb_host *h, enum devctl_cmd c, int arg)
 {
-        return -1;
+       return -1;
 }
 
 static int dummy_isoctl(struct hpsb_iso *iso, enum isoctl_cmd command, unsigned long arg)
@@ -75,9 +75,9 @@ static int dummy_isoctl(struct hpsb_iso *iso, enum isoctl_cmd command, unsigned
 }
 
 static struct hpsb_host_driver dummy_driver = {
-        .transmit_packet = dummy_transmit_packet,
-        .devctl =          dummy_devctl,
-       .isoctl =          dummy_isoctl
+       .transmit_packet = dummy_transmit_packet,
+       .devctl =          dummy_devctl,
+       .isoctl =          dummy_isoctl
 };
 
 static int alloc_hostnum_cb(struct hpsb_host *host, void *__data)
@@ -90,6 +90,16 @@ static int alloc_hostnum_cb(struct hpsb_host *host, void *__data)
        return 0;
 }
 
+/*
+ * The pending_packet_queue is special in that it's processed
+ * from hardirq context too (such as hpsb_bus_reset()). Hence
+ * split the lock class from the usual networking skb-head
+ * lock class by using a separate key for it:
+ */
+static struct lock_class_key pending_packet_queue_key;
+
+static DEFINE_MUTEX(host_num_alloc);
+
 /**
  * hpsb_alloc_host - allocate a new host controller.
  * @drv: the driver that will manage the host controller
@@ -102,21 +112,19 @@ static int alloc_hostnum_cb(struct hpsb_host *host, void *__data)
  * driver specific parts, enable the controller and make it available
  * to the general subsystem using hpsb_add_host().
  *
- * Return Value: a pointer to the &hpsb_host if succesful, %NULL if
+ * Return Value: a pointer to the &hpsb_host if successful, %NULL if
  * no memory was available.
  */
-static DECLARE_MUTEX(host_num_alloc);
-
 struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra,
                                  struct device *dev)
 {
-        struct hpsb_host *h;
+       struct hpsb_host *h;
        int i;
        int hostnum = 0;
 
-        h = kmalloc(sizeof(struct hpsb_host) + extra, SLAB_KERNEL);
-        if (!h) return NULL;
-        memset(h, 0, sizeof(struct hpsb_host) + extra);
+       h = kzalloc(sizeof(*h) + extra, SLAB_KERNEL);
+       if (!h)
+               return NULL;
 
        h->csr.rom = csr1212_create_csr(&csr_bus_ops, CSR_BUS_INFO_SIZE, h);
        if (!h->csr.rom) {
@@ -125,9 +133,11 @@ struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra,
        }
 
        h->hostdata = h + 1;
-        h->driver = drv;
+       h->driver = drv;
 
        skb_queue_head_init(&h->pending_packet_queue);
+       lockdep_set_class(&h->pending_packet_queue.lock,
+                          &pending_packet_queue_key);
        INIT_LIST_HEAD(&h->addr_space);
 
        for (i = 2; i < 16; i++)
@@ -145,10 +155,10 @@ struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra,
        h->timeout.function = abort_timedouts;
        h->timeout_interval = HZ / 20; // 50ms by default
 
-        h->topology_map = h->csr.topology_map + 3;
-        h->speed_map = (u8 *)(h->csr.speed_map + 2);
+       h->topology_map = h->csr.topology_map + 3;
+       h->speed_map = (u8 *)(h->csr.speed_map + 2);
 
-       down(&host_num_alloc);
+       mutex_lock(&host_num_alloc);
 
        while (nodemgr_for_each_host(&hostnum, alloc_hostnum_cb))
                hostnum++;
@@ -167,7 +177,7 @@ struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra,
        class_device_register(&h->class_dev);
        get_device(&h->device);
 
-       up(&host_num_alloc);
+       mutex_unlock(&host_num_alloc);
 
        return h;
 }
@@ -186,14 +196,14 @@ int hpsb_add_host(struct hpsb_host *host)
 
 void hpsb_remove_host(struct hpsb_host *host)
 {
-        host->is_shutdown = 1;
+       host->is_shutdown = 1;
 
        cancel_delayed_work(&host->delayed_reset);
        flush_scheduled_work();
 
-        host->driver = &dummy_driver;
+       host->driver = &dummy_driver;
 
-        highlevel_remove_host(host);
+       highlevel_remove_host(host);
 
        hpsb_remove_extra_config_roms(host);