const: constify remaining dev_pm_ops
[safe/jmp/linux-2.6] / net / iucv / iucv.c
index 0e9f212..fd8b283 100644 (file)
@@ -11,6 +11,8 @@
  *     Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com)
  *    Rewritten for af_iucv:
  *     Martin Schwidefsky <schwidefsky@de.ibm.com>
+ *    PM functions:
+ *     Ursula Braun (ursula.braun@de.ibm.com)
  *
  * Documentation used:
  *    The original source
@@ -77,9 +79,32 @@ static int iucv_bus_match(struct device *dev, struct device_driver *drv)
        return 0;
 }
 
+enum iucv_pm_states {
+       IUCV_PM_INITIAL = 0,
+       IUCV_PM_FREEZING = 1,
+       IUCV_PM_THAWING = 2,
+       IUCV_PM_RESTORING = 3,
+};
+static enum iucv_pm_states iucv_pm_state;
+
+static int iucv_pm_prepare(struct device *);
+static void iucv_pm_complete(struct device *);
+static int iucv_pm_freeze(struct device *);
+static int iucv_pm_thaw(struct device *);
+static int iucv_pm_restore(struct device *);
+
+static const struct dev_pm_ops iucv_pm_ops = {
+       .prepare = iucv_pm_prepare,
+       .complete = iucv_pm_complete,
+       .freeze = iucv_pm_freeze,
+       .thaw = iucv_pm_thaw,
+       .restore = iucv_pm_restore,
+};
+
 struct bus_type iucv_bus = {
        .name = "iucv",
        .match = iucv_bus_match,
+       .pm = &iucv_pm_ops,
 };
 EXPORT_SYMBOL(iucv_bus);
 
@@ -149,6 +174,7 @@ enum iucv_command_codes {
        IUCV_RESUME = 14,
        IUCV_SEVER = 15,
        IUCV_SETMASK = 16,
+       IUCV_SETCONTROLMASK = 17,
 };
 
 /*
@@ -336,7 +362,7 @@ static int iucv_query_maxconn(void)
                "       srl     %0,28\n"
                : "=d" (ccode), "+d" (reg0), "+d" (reg1) : : "cc");
        if (ccode == 0)
-               iucv_max_pathid = reg0;
+               iucv_max_pathid = reg1;
        kfree(param);
        return ccode ? -EPERM : 0;
 }
@@ -366,6 +392,18 @@ static void iucv_allow_cpu(void *data)
        parm->set_mask.ipmask = 0xf8;
        iucv_call_b2f0(IUCV_SETMASK, parm);
 
+       /*
+        * Enable all iucv control interrupts.
+        * ipmask contains bits for the different interrupts
+        *      0x80 - Flag to allow pending connections interrupts
+        *      0x40 - Flag to allow connection complete interrupts
+        *      0x20 - Flag to allow connection severed interrupts
+        *      0x10 - Flag to allow connection quiesced interrupts
+        *      0x08 - Flag to allow connection resumed interrupts
+        */
+       memset(parm, 0, sizeof(union iucv_param));
+       parm->set_mask.ipmask = 0xf8;
+       iucv_call_b2f0(IUCV_SETCONTROLMASK, parm);
        /* Set indication that iucv interrupts are allowed for this cpu. */
        cpu_set(cpu, iucv_irq_cpumask);
 }
@@ -391,6 +429,31 @@ static void iucv_block_cpu(void *data)
 }
 
 /**
+ * iucv_block_cpu_almost
+ * @data: unused
+ *
+ * Allow connection-severed interrupts only on this cpu.
+ */
+static void iucv_block_cpu_almost(void *data)
+{
+       int cpu = smp_processor_id();
+       union iucv_param *parm;
+
+       /* Allow iucv control interrupts only */
+       parm = iucv_param_irq[cpu];
+       memset(parm, 0, sizeof(union iucv_param));
+       parm->set_mask.ipmask = 0x08;
+       iucv_call_b2f0(IUCV_SETMASK, parm);
+       /* Allow iucv-severed interrupt only */
+       memset(parm, 0, sizeof(union iucv_param));
+       parm->set_mask.ipmask = 0x20;
+       iucv_call_b2f0(IUCV_SETCONTROLMASK, parm);
+
+       /* Clear indication that iucv interrupts are allowed for this cpu. */
+       cpu_clear(cpu, iucv_irq_cpumask);
+}
+
+/**
  * iucv_declare_cpu
  * @data: unused
  *
@@ -801,7 +864,7 @@ int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
        int rc;
 
        local_bh_disable();
-       if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
+       if (cpus_empty(iucv_buffer_cpumask)) {
                rc = -EIO;
                goto out;
        }
@@ -850,7 +913,7 @@ int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
 
        spin_lock_bh(&iucv_table_lock);
        iucv_cleanup_queue();
-       if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
+       if (cpus_empty(iucv_buffer_cpumask)) {
                rc = -EIO;
                goto out;
        }
@@ -910,7 +973,7 @@ int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
        int rc;
 
        local_bh_disable();
-       if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
+       if (cpus_empty(iucv_buffer_cpumask)) {
                rc = -EIO;
                goto out;
        }
@@ -942,7 +1005,7 @@ int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
        int rc;
 
        local_bh_disable();
-       if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
+       if (cpus_empty(iucv_buffer_cpumask)) {
                rc = -EIO;
                goto out;
        }
@@ -971,7 +1034,7 @@ int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
        int rc;
 
        preempt_disable();
-       if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
+       if (cpus_empty(iucv_buffer_cpumask)) {
                rc = -EIO;
                goto out;
        }
@@ -1005,7 +1068,7 @@ int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
        int rc;
 
        local_bh_disable();
-       if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
+       if (cpus_empty(iucv_buffer_cpumask)) {
                rc = -EIO;
                goto out;
        }
@@ -1097,7 +1160,7 @@ int __iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
        if (msg->flags & IUCV_IPRMDATA)
                return iucv_message_receive_iprmdata(path, msg, flags,
                                                     buffer, size, residual);
-       if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
+       if (cpus_empty(iucv_buffer_cpumask)) {
                rc = -EIO;
                goto out;
        }
@@ -1170,7 +1233,7 @@ int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
        int rc;
 
        local_bh_disable();
-       if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
+       if (cpus_empty(iucv_buffer_cpumask)) {
                rc = -EIO;
                goto out;
        }
@@ -1209,7 +1272,7 @@ int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
        int rc;
 
        local_bh_disable();
-       if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
+       if (cpus_empty(iucv_buffer_cpumask)) {
                rc = -EIO;
                goto out;
        }
@@ -1259,7 +1322,7 @@ int __iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
        union iucv_param *parm;
        int rc;
 
-       if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
+       if (cpus_empty(iucv_buffer_cpumask)) {
                rc = -EIO;
                goto out;
        }
@@ -1346,7 +1409,7 @@ int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
        int rc;
 
        local_bh_disable();
-       if (!cpu_isset(smp_processor_id(), iucv_buffer_cpumask)) {
+       if (cpus_empty(iucv_buffer_cpumask)) {
                rc = -EIO;
                goto out;
        }
@@ -1705,7 +1768,6 @@ static void iucv_tasklet_fn(unsigned long ignored)
  */
 static void iucv_work_fn(struct work_struct *work)
 {
-       typedef void iucv_irq_fn(struct iucv_irq_data *);
        LIST_HEAD(work_queue);
        struct iucv_irq_list *p, *n;
 
@@ -1766,6 +1828,147 @@ static void iucv_external_interrupt(u16 code)
        spin_unlock(&iucv_queue_lock);
 }
 
+static int iucv_pm_prepare(struct device *dev)
+{
+       int rc = 0;
+
+#ifdef CONFIG_PM_DEBUG
+       printk(KERN_INFO "iucv_pm_prepare\n");
+#endif
+       if (dev->driver && dev->driver->pm && dev->driver->pm->prepare)
+               rc = dev->driver->pm->prepare(dev);
+       return rc;
+}
+
+static void iucv_pm_complete(struct device *dev)
+{
+#ifdef CONFIG_PM_DEBUG
+       printk(KERN_INFO "iucv_pm_complete\n");
+#endif
+       if (dev->driver && dev->driver->pm && dev->driver->pm->complete)
+               dev->driver->pm->complete(dev);
+}
+
+/**
+ * iucv_path_table_empty() - determine if iucv path table is empty
+ *
+ * Returns 0 if there are still iucv pathes defined
+ *        1 if there are no iucv pathes defined
+ */
+int iucv_path_table_empty(void)
+{
+       int i;
+
+       for (i = 0; i < iucv_max_pathid; i++) {
+               if (iucv_path_table[i])
+                       return 0;
+       }
+       return 1;
+}
+
+/**
+ * iucv_pm_freeze() - Freeze PM callback
+ * @dev:       iucv-based device
+ *
+ * disable iucv interrupts
+ * invoke callback function of the iucv-based driver
+ * shut down iucv, if no iucv-pathes are established anymore
+ */
+static int iucv_pm_freeze(struct device *dev)
+{
+       int cpu;
+       struct iucv_irq_list *p, *n;
+       int rc = 0;
+
+#ifdef CONFIG_PM_DEBUG
+       printk(KERN_WARNING "iucv_pm_freeze\n");
+#endif
+       if (iucv_pm_state != IUCV_PM_FREEZING) {
+               for_each_cpu_mask_nr(cpu, iucv_irq_cpumask)
+                       smp_call_function_single(cpu, iucv_block_cpu_almost,
+                                                NULL, 1);
+               cancel_work_sync(&iucv_work);
+               list_for_each_entry_safe(p, n, &iucv_work_queue, list) {
+                       list_del_init(&p->list);
+                       iucv_sever_pathid(p->data.ippathid,
+                                         iucv_error_no_listener);
+                       kfree(p);
+               }
+       }
+       iucv_pm_state = IUCV_PM_FREEZING;
+       if (dev->driver && dev->driver->pm && dev->driver->pm->freeze)
+               rc = dev->driver->pm->freeze(dev);
+       if (iucv_path_table_empty())
+               iucv_disable();
+       return rc;
+}
+
+/**
+ * iucv_pm_thaw() - Thaw PM callback
+ * @dev:       iucv-based device
+ *
+ * make iucv ready for use again: allocate path table, declare interrupt buffers
+ *                               and enable iucv interrupts
+ * invoke callback function of the iucv-based driver
+ */
+static int iucv_pm_thaw(struct device *dev)
+{
+       int rc = 0;
+
+#ifdef CONFIG_PM_DEBUG
+       printk(KERN_WARNING "iucv_pm_thaw\n");
+#endif
+       iucv_pm_state = IUCV_PM_THAWING;
+       if (!iucv_path_table) {
+               rc = iucv_enable();
+               if (rc)
+                       goto out;
+       }
+       if (cpus_empty(iucv_irq_cpumask)) {
+               if (iucv_nonsmp_handler)
+                       /* enable interrupts on one cpu */
+                       iucv_allow_cpu(NULL);
+               else
+                       /* enable interrupts on all cpus */
+                       iucv_setmask_mp();
+       }
+       if (dev->driver && dev->driver->pm && dev->driver->pm->thaw)
+               rc = dev->driver->pm->thaw(dev);
+out:
+       return rc;
+}
+
+/**
+ * iucv_pm_restore() - Restore PM callback
+ * @dev:       iucv-based device
+ *
+ * make iucv ready for use again: allocate path table, declare interrupt buffers
+ *                               and enable iucv interrupts
+ * invoke callback function of the iucv-based driver
+ */
+static int iucv_pm_restore(struct device *dev)
+{
+       int rc = 0;
+
+#ifdef CONFIG_PM_DEBUG
+       printk(KERN_WARNING "iucv_pm_restore %p\n", iucv_path_table);
+#endif
+       if ((iucv_pm_state != IUCV_PM_RESTORING) && iucv_path_table)
+               pr_warning("Suspending Linux did not completely close all IUCV "
+                       "connections\n");
+       iucv_pm_state = IUCV_PM_RESTORING;
+       if (cpus_empty(iucv_irq_cpumask)) {
+               rc = iucv_query_maxconn();
+               rc = iucv_enable();
+               if (rc)
+                       goto out;
+       }
+       if (dev->driver && dev->driver->pm && dev->driver->pm->restore)
+               rc = dev->driver->pm->restore(dev);
+out:
+       return rc;
+}
+
 /**
  * iucv_init
  *