]> err.no Git - linux-2.6/blobdiff - drivers/ieee1394/nodemgr.c
Merge branch 'for_paulus' of master.kernel.org:/pub/scm/linux/kernel/git/galak/powerp...
[linux-2.6] / drivers / ieee1394 / nodemgr.c
index 801f606192361ea3deb56fa9b92c74d5d783f583..61307ca296ae4745c26c2242d24aae238c2361a5 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/delay.h>
 #include <linux/kthread.h>
+#include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/freezer.h>
 #include <asm/atomic.h>
@@ -99,7 +100,7 @@ static int nodemgr_check_speed(struct nodemgr_csr_info *ci, u64 addr,
 }
 
 static int nodemgr_bus_read(struct csr1212_csr *csr, u64 addr, u16 length,
-                            void *buffer, void *__ci)
+                           void *buffer, void *__ci)
 {
        struct nodemgr_csr_info *ci = (struct nodemgr_csr_info*)__ci;
        int i, error;
@@ -260,9 +261,20 @@ static struct device nodemgr_dev_template_ne = {
        .release        = nodemgr_release_ne,
 };
 
+/* This dummy driver prevents the host devices from being scanned. We have no
+ * useful drivers for them yet, and there would be a deadlock possible if the
+ * driver core scans the host device while the host's low-level driver (i.e.
+ * the host's parent device) is being removed. */
+static struct device_driver nodemgr_mid_layer_driver = {
+       .bus            = &ieee1394_bus_type,
+       .name           = "nodemgr",
+       .owner          = THIS_MODULE,
+};
+
 struct device nodemgr_dev_template_host = {
        .bus            = &ieee1394_bus_type,
        .release        = nodemgr_release_host,
+       .driver         = &nodemgr_mid_layer_driver,
 };
 
 
@@ -307,8 +319,8 @@ static ssize_t fw_drv_show_##field (struct device_driver *drv, char *buf) \
        return sprintf(buf, format_string, (type)driver->field);\
 }                                                              \
 static struct driver_attribute driver_attr_drv_##field = {     \
-        .attr = {.name = __stringify(field), .mode = S_IRUGO },        \
-        .show   = fw_drv_show_##field,                         \
+       .attr = {.name = __stringify(field), .mode = S_IRUGO }, \
+       .show   = fw_drv_show_##field,                          \
 };
 
 
@@ -529,7 +541,7 @@ static ssize_t fw_show_drv_device_ids(struct device_driver *drv, char *buf)
        int length = 0;
        char *scratch = buf;
 
-        driver = container_of(drv, struct hpsb_protocol_driver, driver);
+       driver = container_of(drv, struct hpsb_protocol_driver, driver);
 
        for (id = driver->id_table; id->match_flags != 0; id++) {
                int need_coma = 0;
@@ -696,8 +708,8 @@ fail:
 
 static int nodemgr_bus_match(struct device * dev, struct device_driver * drv)
 {
-        struct hpsb_protocol_driver *driver;
-        struct unit_directory *ud;
+       struct hpsb_protocol_driver *driver;
+       struct unit_directory *ud;
        struct ieee1394_device_id *id;
 
        /* We only match unit directories */
@@ -705,30 +717,33 @@ static int nodemgr_bus_match(struct device * dev, struct device_driver * drv)
                return 0;
 
        ud = container_of(dev, struct unit_directory, device);
-       driver = container_of(drv, struct hpsb_protocol_driver, driver);
-
        if (ud->ne->in_limbo || ud->ignore_driver)
                return 0;
 
-        for (id = driver->id_table; id->match_flags != 0; id++) {
-                if ((id->match_flags & IEEE1394_MATCH_VENDOR_ID) &&
-                    id->vendor_id != ud->vendor_id)
-                        continue;
+       /* We only match drivers of type hpsb_protocol_driver */
+       if (drv == &nodemgr_mid_layer_driver)
+               return 0;
 
-                if ((id->match_flags & IEEE1394_MATCH_MODEL_ID) &&
-                    id->model_id != ud->model_id)
-                        continue;
+       driver = container_of(drv, struct hpsb_protocol_driver, driver);
+       for (id = driver->id_table; id->match_flags != 0; id++) {
+               if ((id->match_flags & IEEE1394_MATCH_VENDOR_ID) &&
+                   id->vendor_id != ud->vendor_id)
+                       continue;
+
+               if ((id->match_flags & IEEE1394_MATCH_MODEL_ID) &&
+                   id->model_id != ud->model_id)
+                       continue;
 
-                if ((id->match_flags & IEEE1394_MATCH_SPECIFIER_ID) &&
-                    id->specifier_id != ud->specifier_id)
-                        continue;
+               if ((id->match_flags & IEEE1394_MATCH_SPECIFIER_ID) &&
+                   id->specifier_id != ud->specifier_id)
+                       continue;
 
-                if ((id->match_flags & IEEE1394_MATCH_VERSION) &&
-                    id->version != ud->version)
-                        continue;
+               if ((id->match_flags & IEEE1394_MATCH_VERSION) &&
+                   id->version != ud->version)
+                       continue;
 
                return 1;
-        }
+       }
 
        return 0;
 }
@@ -739,66 +754,40 @@ static DEFINE_MUTEX(nodemgr_serialize_remove_uds);
 static void nodemgr_remove_uds(struct node_entry *ne)
 {
        struct class_device *cdev;
-       struct unit_directory *ud, **unreg;
-       size_t i, count;
+       struct unit_directory *tmp, *ud;
 
-       /*
-        * This is awkward:
-        * Iteration over nodemgr_ud_class.children has to be protected by
+       /* Iteration over nodemgr_ud_class.children has to be protected by
         * nodemgr_ud_class.sem, but class_device_unregister() will eventually
-        * take nodemgr_ud_class.sem too. Therefore store all uds to be
-        * unregistered in a temporary array, release the semaphore, and then
-        * unregister the uds.
-        *
-        * Since nodemgr_remove_uds can also run in other contexts than the
-        * knodemgrds (which are currently globally serialized), protect the
+        * take nodemgr_ud_class.sem too. Therefore pick out one ud at a time,
+        * release the semaphore, and then unregister the ud. Since this code
+        * may be called from other contexts besides the knodemgrds, protect the
         * gap after release of the semaphore by nodemgr_serialize_remove_uds.
         */
-
        mutex_lock(&nodemgr_serialize_remove_uds);
-
-       down(&nodemgr_ud_class.sem);
-       count = 0;
-       list_for_each_entry(cdev, &nodemgr_ud_class.children, node) {
-               ud = container_of(cdev, struct unit_directory, class_dev);
-               if (ud->ne == ne)
-                       count++;
-       }
-       if (!count) {
-               up(&nodemgr_ud_class.sem);
-               mutex_unlock(&nodemgr_serialize_remove_uds);
-               return;
-       }
-       unreg = kcalloc(count, sizeof(*unreg), GFP_KERNEL);
-       if (!unreg) {
-               HPSB_ERR("NodeMgr: out of memory in nodemgr_remove_uds");
-               up(&nodemgr_ud_class.sem);
-               mutex_unlock(&nodemgr_serialize_remove_uds);
-               return;
-       }
-       i = 0;
-       list_for_each_entry(cdev, &nodemgr_ud_class.children, node) {
-               ud = container_of(cdev, struct unit_directory, class_dev);
-               if (ud->ne == ne) {
-                       BUG_ON(i >= count);
-                       unreg[i++] = ud;
+       for (;;) {
+               ud = NULL;
+               down(&nodemgr_ud_class.sem);
+               list_for_each_entry(cdev, &nodemgr_ud_class.children, node) {
+                       tmp = container_of(cdev, struct unit_directory,
+                                          class_dev);
+                       if (tmp->ne == ne) {
+                               ud = tmp;
+                               break;
+                       }
                }
+               up(&nodemgr_ud_class.sem);
+               if (ud == NULL)
+                       break;
+               class_device_unregister(&ud->class_dev);
+               device_unregister(&ud->device);
        }
-       up(&nodemgr_ud_class.sem);
-
-       for (i = 0; i < count; i++) {
-               class_device_unregister(&unreg[i]->class_dev);
-               device_unregister(&unreg[i]->device);
-       }
-       kfree(unreg);
-
        mutex_unlock(&nodemgr_serialize_remove_uds);
 }
 
 
 static void nodemgr_remove_ne(struct node_entry *ne)
 {
-       struct device *dev = &ne->device;
+       struct device *dev;
 
        dev = get_device(&ne->device);
        if (!dev)
@@ -837,16 +826,16 @@ static void nodemgr_update_bus_options(struct node_entry *ne)
 #endif
        quadlet_t busoptions = be32_to_cpu(ne->csr->bus_info_data[2]);
 
-       ne->busopt.irmc         = (busoptions >> 31) & 1;
-       ne->busopt.cmc          = (busoptions >> 30) & 1;
-       ne->busopt.isc          = (busoptions >> 29) & 1;
-       ne->busopt.bmc          = (busoptions >> 28) & 1;
-       ne->busopt.pmc          = (busoptions >> 27) & 1;
-       ne->busopt.cyc_clk_acc  = (busoptions >> 16) & 0xff;
-       ne->busopt.max_rec      = 1 << (((busoptions >> 12) & 0xf) + 1);
+       ne->busopt.irmc         = (busoptions >> 31) & 1;
+       ne->busopt.cmc          = (busoptions >> 30) & 1;
+       ne->busopt.isc          = (busoptions >> 29) & 1;
+       ne->busopt.bmc          = (busoptions >> 28) & 1;
+       ne->busopt.pmc          = (busoptions >> 27) & 1;
+       ne->busopt.cyc_clk_acc  = (busoptions >> 16) & 0xff;
+       ne->busopt.max_rec      = 1 << (((busoptions >> 12) & 0xf) + 1);
        ne->busopt.max_rom      = (busoptions >> 8) & 0x3;
-       ne->busopt.generation   = (busoptions >> 4) & 0xf;
-       ne->busopt.lnkspd       = busoptions & 0x7;
+       ne->busopt.generation   = (busoptions >> 4) & 0xf;
+       ne->busopt.lnkspd       = busoptions & 0x7;
 
        HPSB_VERBOSE("NodeMgr: raw=0x%08x irmc=%d cmc=%d isc=%d bmc=%d pmc=%d "
                     "cyc_clk_acc=%d max_rec=%d max_rom=%d gen=%d lspd=%d",
@@ -939,7 +928,7 @@ static struct node_entry *find_entry_by_guid(u64 guid)
        }
        up(&nodemgr_ne_class.sem);
 
-        return ret_ne;
+       return ret_ne;
 }
 
 
@@ -1267,12 +1256,19 @@ static int nodemgr_uevent(struct class_device *cdev, char **envp, int num_envp,
 #endif /* CONFIG_HOTPLUG */
 
 
-int hpsb_register_protocol(struct hpsb_protocol_driver *driver)
+int __hpsb_register_protocol(struct hpsb_protocol_driver *drv,
+                            struct module *owner)
 {
+       int error;
+
+       drv->driver.bus = &ieee1394_bus_type;
+       drv->driver.owner = owner;
+       drv->driver.name = drv->name;
+
        /* This will cause a probe for devices */
-       int error = driver_register(&driver->driver);
+       error = driver_register(&drv->driver);
        if (!error)
-               nodemgr_create_drv_files(driver);
+               nodemgr_create_drv_files(drv);
        return error;
 }
 
@@ -1401,22 +1397,22 @@ static void nodemgr_node_scan_one(struct host_info *hi,
 
 static void nodemgr_node_scan(struct host_info *hi, int generation)
 {
-        int count;
-        struct hpsb_host *host = hi->host;
-        struct selfid *sid = (struct selfid *)host->topology_map;
-        nodeid_t nodeid = LOCAL_BUS;
+       int count;
+       struct hpsb_host *host = hi->host;
+       struct selfid *sid = (struct selfid *)host->topology_map;
+       nodeid_t nodeid = LOCAL_BUS;
 
-        /* Scan each node on the bus */
-        for (count = host->selfid_count; count; count--, sid++) {
-                if (sid->extended)
-                        continue;
+       /* Scan each node on the bus */
+       for (count = host->selfid_count; count; count--, sid++) {
+               if (sid->extended)
+                       continue;
 
-                if (!sid->link_active) {
-                        nodeid++;
-                        continue;
-                }
-                nodemgr_node_scan_one(hi, nodeid++, generation);
-        }
+               if (!sid->link_active) {
+                       nodeid++;
+                       continue;
+               }
+               nodemgr_node_scan_one(hi, nodeid++, generation);
+       }
 }
 
 
@@ -1582,7 +1578,7 @@ static void nodemgr_node_probe(struct host_info *hi, int generation)
                if (ne->needs_probe)
                        nodemgr_probe_ne(hi, ne, generation);
        }
-        up(&nodemgr_ne_class.sem);
+       up(&nodemgr_ne_class.sem);
 
 
        /* If we had a bus reset while we were scanning the bus, it is
@@ -1600,9 +1596,8 @@ static void nodemgr_node_probe(struct host_info *hi, int generation)
         * just removed.  */
 
        if (generation == get_hpsb_generation(host))
-               WARN_ON(bus_rescan_devices(&ieee1394_bus_type));
-
-       return;
+               if (bus_rescan_devices(&ieee1394_bus_type))
+                       HPSB_DEBUG("bus_rescan_devices had an error");
 }
 
 static int nodemgr_send_resume_packet(struct hpsb_host *host)
@@ -1827,10 +1822,10 @@ int nodemgr_for_each_host(void *__data, int (*cb)(struct hpsb_host *, void *))
 
 void hpsb_node_fill_packet(struct node_entry *ne, struct hpsb_packet *pkt)
 {
-        pkt->host = ne->host;
-        pkt->generation = ne->generation;
+       pkt->host = ne->host;
+       pkt->generation = ne->generation;
        barrier();
-        pkt->node_id = ne->nodeid;
+       pkt->node_id = ne->nodeid;
 }
 
 int hpsb_node_write(struct node_entry *ne, u64 addr,
@@ -1901,14 +1896,14 @@ int init_ieee1394_nodemgr(void)
                class_unregister(&nodemgr_ne_class);
                return error;
        }
-
+       error = driver_register(&nodemgr_mid_layer_driver);
        hpsb_register_highlevel(&nodemgr_highlevel);
        return 0;
 }
 
 void cleanup_ieee1394_nodemgr(void)
 {
-        hpsb_unregister_highlevel(&nodemgr_highlevel);
+       hpsb_unregister_highlevel(&nodemgr_highlevel);
 
        class_unregister(&nodemgr_ud_class);
        class_unregister(&nodemgr_ne_class);