const: constify remaining dev_pm_ops
[safe/jmp/linux-2.6] / net / iucv / iucv.c
index 7f82b76..fd8b283 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * IUCV base infrastructure.
  *
- * Copyright 2001, 2006 IBM Deutschland Entwicklung GmbH, IBM Corporation
+ * Copyright IBM Corp. 2001, 2009
+ *
  * Author(s):
  *    Original source:
  *     Alan Altmark (Alan_Altmark@us.ibm.com)  Sept. 2000
@@ -10,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
@@ -30,6 +33,9 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#define KMSG_COMPONENT "iucv"
+#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
+
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/spinlock.h>
 #include <linux/err.h>
 #include <linux/device.h>
 #include <linux/cpu.h>
+#include <linux/reboot.h>
 #include <net/iucv/iucv.h>
 #include <asm/atomic.h>
 #include <asm/ebcdic.h>
 #include <asm/io.h>
 #include <asm/s390_ext.h>
-#include <asm/s390_rdev.h>
 #include <asm/smp.h>
 
 /*
@@ -73,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);
 
@@ -145,6 +174,7 @@ enum iucv_command_codes {
        IUCV_RESUME = 14,
        IUCV_SEVER = 15,
        IUCV_SETMASK = 16,
+       IUCV_SETCONTROLMASK = 17,
 };
 
 /*
@@ -278,6 +308,7 @@ union iucv_param {
  * Anchor for per-cpu IUCV command parameter block.
  */
 static union iucv_param *iucv_param[NR_CPUS];
+static union iucv_param *iucv_param_irq[NR_CPUS];
 
 /**
  * iucv_call_b2f0
@@ -331,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;
 }
@@ -356,11 +387,23 @@ static void iucv_allow_cpu(void *data)
         *      0x10 - Flag to allow priority message completion interrupts
         *      0x08 - Flag to allow IUCV control interrupts
         */
-       parm = iucv_param[cpu];
+       parm = iucv_param_irq[cpu];
        memset(parm, 0, sizeof(union iucv_param));
        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);
 }
@@ -377,9 +420,34 @@ static void iucv_block_cpu(void *data)
        union iucv_param *parm;
 
        /* Disable all iucv interrupts. */
-       parm = iucv_param[cpu];
+       parm = iucv_param_irq[cpu];
+       memset(parm, 0, sizeof(union iucv_param));
+       iucv_call_b2f0(IUCV_SETMASK, parm);
+
+       /* Clear indication that iucv interrupts are allowed for this cpu. */
+       cpu_clear(cpu, iucv_irq_cpumask);
+}
+
+/**
+ * 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);
@@ -401,7 +469,7 @@ static void iucv_declare_cpu(void *data)
                return;
 
        /* Declare interrupt buffer. */
-       parm = iucv_param[cpu];
+       parm = iucv_param_irq[cpu];
        memset(parm, 0, sizeof(union iucv_param));
        parm->db.ipbfadr1 = virt_to_phys(iucv_irq_data[cpu]);
        rc = iucv_call_b2f0(IUCV_DECLARE_BUFFER, parm);
@@ -424,8 +492,8 @@ static void iucv_declare_cpu(void *data)
                        err = "Paging or storage error";
                        break;
                }
-               printk(KERN_WARNING "iucv_register: iucv_declare_buffer "
-                      "on cpu %i returned error 0x%02x (%s)\n", cpu, rc, err);
+               pr_warning("Defining an interrupt buffer on CPU %i"
+                          " failed with 0x%02x (%s)\n", cpu, rc, err);
                return;
        }
 
@@ -458,7 +526,7 @@ static void iucv_retrieve_cpu(void *data)
        iucv_block_cpu(NULL);
 
        /* Retrieve interrupt buffer. */
-       parm = iucv_param[cpu];
+       parm = iucv_param_irq[cpu];
        iucv_call_b2f0(IUCV_RETRIEVE_BUFFER, parm);
 
        /* Clear indication that an iucv buffer exists for this cpu. */
@@ -474,14 +542,14 @@ static void iucv_setmask_mp(void)
 {
        int cpu;
 
-       preempt_disable();
+       get_online_cpus();
        for_each_online_cpu(cpu)
                /* Enable all cpus with a declared buffer. */
                if (cpu_isset(cpu, iucv_buffer_cpumask) &&
                    !cpu_isset(cpu, iucv_irq_cpumask))
                        smp_call_function_single(cpu, iucv_allow_cpu,
-                                                NULL, 0, 1);
-       preempt_enable();
+                                                NULL, 1);
+       put_online_cpus();
 }
 
 /**
@@ -497,8 +565,8 @@ static void iucv_setmask_up(void)
        /* Disable all cpu but the first in cpu_irq_cpumask. */
        cpumask = iucv_irq_cpumask;
        cpu_clear(first_cpu(iucv_irq_cpumask), cpumask);
-       for_each_cpu_mask(cpu, cpumask)
-               smp_call_function_single(cpu, iucv_block_cpu, NULL, 0, 1);
+       for_each_cpu_mask_nr(cpu, cpumask)
+               smp_call_function_single(cpu, iucv_block_cpu, NULL, 1);
 }
 
 /**
@@ -514,6 +582,7 @@ static int iucv_enable(void)
        size_t alloc_size;
        int cpu, rc;
 
+       get_online_cpus();
        rc = -ENOMEM;
        alloc_size = iucv_max_pathid * sizeof(struct iucv_path);
        iucv_path_table = kzalloc(alloc_size, GFP_KERNEL);
@@ -521,18 +590,17 @@ static int iucv_enable(void)
                goto out;
        /* Declare per cpu buffers. */
        rc = -EIO;
-       preempt_disable();
        for_each_online_cpu(cpu)
-               smp_call_function_single(cpu, iucv_declare_cpu, NULL, 0, 1);
-       preempt_enable();
+               smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
        if (cpus_empty(iucv_buffer_cpumask))
                /* No cpu could declare an iucv buffer. */
-               goto out_path;
+               goto out;
+       put_online_cpus();
        return 0;
-
-out_path:
-       kfree(iucv_path_table);
 out:
+       kfree(iucv_path_table);
+       iucv_path_table = NULL;
+       put_online_cpus();
        return rc;
 }
 
@@ -545,8 +613,11 @@ out:
  */
 static void iucv_disable(void)
 {
-       on_each_cpu(iucv_retrieve_cpu, NULL, 0, 1);
+       get_online_cpus();
+       on_each_cpu(iucv_retrieve_cpu, NULL, 1);
        kfree(iucv_path_table);
+       iucv_path_table = NULL;
+       put_online_cpus();
 }
 
 static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
@@ -564,13 +635,27 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
                        return NOTIFY_BAD;
                iucv_param[cpu] = kmalloc_node(sizeof(union iucv_param),
                                     GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
-               if (!iucv_param[cpu])
+               if (!iucv_param[cpu]) {
+                       kfree(iucv_irq_data[cpu]);
+                       iucv_irq_data[cpu] = NULL;
+                       return NOTIFY_BAD;
+               }
+               iucv_param_irq[cpu] = kmalloc_node(sizeof(union iucv_param),
+                                       GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
+               if (!iucv_param_irq[cpu]) {
+                       kfree(iucv_param[cpu]);
+                       iucv_param[cpu] = NULL;
+                       kfree(iucv_irq_data[cpu]);
+                       iucv_irq_data[cpu] = NULL;
                        return NOTIFY_BAD;
+               }
                break;
        case CPU_UP_CANCELED:
        case CPU_UP_CANCELED_FROZEN:
        case CPU_DEAD:
        case CPU_DEAD_FROZEN:
+               kfree(iucv_param_irq[cpu]);
+               iucv_param_irq[cpu] = NULL;
                kfree(iucv_param[cpu]);
                iucv_param[cpu] = NULL;
                kfree(iucv_irq_data[cpu]);
@@ -580,25 +665,29 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
        case CPU_ONLINE_FROZEN:
        case CPU_DOWN_FAILED:
        case CPU_DOWN_FAILED_FROZEN:
-               smp_call_function_single(cpu, iucv_declare_cpu, NULL, 0, 1);
+               if (!iucv_path_table)
+                       break;
+               smp_call_function_single(cpu, iucv_declare_cpu, NULL, 1);
                break;
        case CPU_DOWN_PREPARE:
        case CPU_DOWN_PREPARE_FROZEN:
+               if (!iucv_path_table)
+                       break;
                cpumask = iucv_buffer_cpumask;
                cpu_clear(cpu, cpumask);
                if (cpus_empty(cpumask))
                        /* Can't offline last IUCV enabled cpu. */
                        return NOTIFY_BAD;
-               smp_call_function_single(cpu, iucv_retrieve_cpu, NULL, 0, 1);
+               smp_call_function_single(cpu, iucv_retrieve_cpu, NULL, 1);
                if (cpus_empty(iucv_irq_cpumask))
                        smp_call_function_single(first_cpu(iucv_buffer_cpumask),
-                                                iucv_allow_cpu, NULL, 0, 1);
+                                                iucv_allow_cpu, NULL, 1);
                break;
        }
        return NOTIFY_OK;
 }
 
-static struct notifier_block __cpuinitdata iucv_cpu_notifier = {
+static struct notifier_block __refdata iucv_cpu_notifier = {
        .notifier_call = iucv_cpu_notify,
 };
 
@@ -613,7 +702,7 @@ static int iucv_sever_pathid(u16 pathid, u8 userdata[16])
 {
        union iucv_param *parm;
 
-       parm = iucv_param[smp_processor_id()];
+       parm = iucv_param_irq[smp_processor_id()];
        memset(parm, 0, sizeof(union iucv_param));
        if (userdata)
                memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
@@ -652,7 +741,7 @@ static void iucv_cleanup_queue(void)
         * pending interrupts force them to the work queue by calling
         * an empty function on all cpus.
         */
-       smp_call_function(__iucv_cleanup_queue, NULL, 0, 1);
+       smp_call_function(__iucv_cleanup_queue, NULL, 1);
        spin_lock_irq(&iucv_queue_lock);
        list_for_each_entry_safe(p, n, &iucv_task_queue, list) {
                /* Remove stale work items from the task queue. */
@@ -734,6 +823,28 @@ void iucv_unregister(struct iucv_handler *handler, int smp)
 }
 EXPORT_SYMBOL(iucv_unregister);
 
+static int iucv_reboot_event(struct notifier_block *this,
+                            unsigned long event, void *ptr)
+{
+       int i, rc;
+
+       get_online_cpus();
+       on_each_cpu(iucv_block_cpu, NULL, 1);
+       preempt_disable();
+       for (i = 0; i < iucv_max_pathid; i++) {
+               if (iucv_path_table[i])
+                       rc = iucv_sever_pathid(i, NULL);
+       }
+       preempt_enable();
+       put_online_cpus();
+       iucv_disable();
+       return NOTIFY_DONE;
+}
+
+static struct notifier_block iucv_reboot_notifier = {
+       .notifier_call = iucv_reboot_event,
+};
+
 /**
  * iucv_path_accept
  * @path: address of iucv path structure
@@ -753,6 +864,10 @@ int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
        int rc;
 
        local_bh_disable();
+       if (cpus_empty(iucv_buffer_cpumask)) {
+               rc = -EIO;
+               goto out;
+       }
        /* Prepare parameter block. */
        parm = iucv_param[smp_processor_id()];
        memset(parm, 0, sizeof(union iucv_param));
@@ -768,6 +883,7 @@ int iucv_path_accept(struct iucv_path *path, struct iucv_handler *handler,
                path->msglim = parm->ctrl.ipmsglim;
                path->flags = parm->ctrl.ipflags1;
        }
+out:
        local_bh_enable();
        return rc;
 }
@@ -797,6 +913,10 @@ int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
 
        spin_lock_bh(&iucv_table_lock);
        iucv_cleanup_queue();
+       if (cpus_empty(iucv_buffer_cpumask)) {
+               rc = -EIO;
+               goto out;
+       }
        parm = iucv_param[smp_processor_id()];
        memset(parm, 0, sizeof(union iucv_param));
        parm->ctrl.ipmsglim = path->msglim;
@@ -831,6 +951,7 @@ int iucv_path_connect(struct iucv_path *path, struct iucv_handler *handler,
                        rc = -EIO;
                }
        }
+out:
        spin_unlock_bh(&iucv_table_lock);
        return rc;
 }
@@ -852,12 +973,17 @@ int iucv_path_quiesce(struct iucv_path *path, u8 userdata[16])
        int rc;
 
        local_bh_disable();
+       if (cpus_empty(iucv_buffer_cpumask)) {
+               rc = -EIO;
+               goto out;
+       }
        parm = iucv_param[smp_processor_id()];
        memset(parm, 0, sizeof(union iucv_param));
        if (userdata)
                memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
        parm->ctrl.ippathid = path->pathid;
        rc = iucv_call_b2f0(IUCV_QUIESCE, parm);
+out:
        local_bh_enable();
        return rc;
 }
@@ -879,12 +1005,17 @@ int iucv_path_resume(struct iucv_path *path, u8 userdata[16])
        int rc;
 
        local_bh_disable();
+       if (cpus_empty(iucv_buffer_cpumask)) {
+               rc = -EIO;
+               goto out;
+       }
        parm = iucv_param[smp_processor_id()];
        memset(parm, 0, sizeof(union iucv_param));
        if (userdata)
                memcpy(parm->ctrl.ipuser, userdata, sizeof(parm->ctrl.ipuser));
        parm->ctrl.ippathid = path->pathid;
        rc = iucv_call_b2f0(IUCV_RESUME, parm);
+out:
        local_bh_enable();
        return rc;
 }
@@ -903,15 +1034,18 @@ int iucv_path_sever(struct iucv_path *path, u8 userdata[16])
        int rc;
 
        preempt_disable();
+       if (cpus_empty(iucv_buffer_cpumask)) {
+               rc = -EIO;
+               goto out;
+       }
        if (iucv_active_cpu != smp_processor_id())
                spin_lock_bh(&iucv_table_lock);
        rc = iucv_sever_pathid(path->pathid, userdata);
-       if (!rc) {
-               iucv_path_table[path->pathid] = NULL;
-               list_del_init(&path->list);
-       }
+       iucv_path_table[path->pathid] = NULL;
+       list_del_init(&path->list);
        if (iucv_active_cpu != smp_processor_id())
                spin_unlock_bh(&iucv_table_lock);
+out:
        preempt_enable();
        return rc;
 }
@@ -934,6 +1068,10 @@ int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
        int rc;
 
        local_bh_disable();
+       if (cpus_empty(iucv_buffer_cpumask)) {
+               rc = -EIO;
+               goto out;
+       }
        parm = iucv_param[smp_processor_id()];
        memset(parm, 0, sizeof(union iucv_param));
        parm->purge.ippathid = path->pathid;
@@ -945,13 +1083,59 @@ int iucv_message_purge(struct iucv_path *path, struct iucv_message *msg,
                msg->audit = (*(u32 *) &parm->purge.ipaudit) >> 8;
                msg->tag = parm->purge.ipmsgtag;
        }
+out:
        local_bh_enable();
        return rc;
 }
 EXPORT_SYMBOL(iucv_message_purge);
 
 /**
- * iucv_message_receive
+ * iucv_message_receive_iprmdata
+ * @path: address of iucv path structure
+ * @msg: address of iucv msg structure
+ * @flags: how the message is received (IUCV_IPBUFLST)
+ * @buffer: address of data buffer or address of struct iucv_array
+ * @size: length of data buffer
+ * @residual:
+ *
+ * Internal function used by iucv_message_receive and __iucv_message_receive
+ * to receive RMDATA data stored in struct iucv_message.
+ */
+static int iucv_message_receive_iprmdata(struct iucv_path *path,
+                                        struct iucv_message *msg,
+                                        u8 flags, void *buffer,
+                                        size_t size, size_t *residual)
+{
+       struct iucv_array *array;
+       u8 *rmmsg;
+       size_t copy;
+
+       /*
+        * Message is 8 bytes long and has been stored to the
+        * message descriptor itself.
+        */
+       if (residual)
+               *residual = abs(size - 8);
+       rmmsg = msg->rmmsg;
+       if (flags & IUCV_IPBUFLST) {
+               /* Copy to struct iucv_array. */
+               size = (size < 8) ? size : 8;
+               for (array = buffer; size > 0; array++) {
+                       copy = min_t(size_t, size, array->length);
+                       memcpy((u8 *)(addr_t) array->address,
+                               rmmsg, copy);
+                       rmmsg += copy;
+                       size -= copy;
+               }
+       } else {
+               /* Copy to direct buffer. */
+               memcpy(buffer, rmmsg, min_t(size_t, size, 8));
+       }
+       return 0;
+}
+
+/**
+ * __iucv_message_receive
  * @path: address of iucv path structure
  * @msg: address of iucv msg structure
  * @flags: how the message is received (IUCV_IPBUFLST)
@@ -963,44 +1147,23 @@ EXPORT_SYMBOL(iucv_message_purge);
  * established paths. This function will deal with RMDATA messages
  * embedded in struct iucv_message as well.
  *
+ * Locking:    no locking
+ *
  * Returns the result from the CP IUCV call.
  */
-int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
-                        u8 flags, void *buffer, size_t size, size_t *residual)
+int __iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
+                          u8 flags, void *buffer, size_t size, size_t *residual)
 {
        union iucv_param *parm;
-       struct iucv_array *array;
-       u8 *rmmsg;
-       size_t copy;
        int rc;
 
-       if (msg->flags & IUCV_IPRMDATA) {
-               /*
-                * Message is 8 bytes long and has been stored to the
-                * message descriptor itself.
-                */
-               rc = (size < 8) ? 5 : 0;
-               if (residual)
-                       *residual = abs(size - 8);
-               rmmsg = msg->rmmsg;
-               if (flags & IUCV_IPBUFLST) {
-                       /* Copy to struct iucv_array. */
-                       size = (size < 8) ? size : 8;
-                       for (array = buffer; size > 0; array++) {
-                               copy = min_t(size_t, size, array->length);
-                               memcpy((u8 *)(addr_t) array->address,
-                                      rmmsg, copy);
-                               rmmsg += copy;
-                               size -= copy;
-                       }
-               } else {
-                       /* Copy to direct buffer. */
-                       memcpy(buffer, rmmsg, min_t(size_t, size, 8));
-               }
-               return 0;
+       if (msg->flags & IUCV_IPRMDATA)
+               return iucv_message_receive_iprmdata(path, msg, flags,
+                                                    buffer, size, residual);
+       if (cpus_empty(iucv_buffer_cpumask)) {
+               rc = -EIO;
+               goto out;
        }
-
-       local_bh_disable();
        parm = iucv_param[smp_processor_id()];
        memset(parm, 0, sizeof(union iucv_param));
        parm->db.ipbfadr1 = (u32)(addr_t) buffer;
@@ -1016,6 +1179,38 @@ int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
                if (residual)
                        *residual = parm->db.ipbfln1f;
        }
+out:
+       return rc;
+}
+EXPORT_SYMBOL(__iucv_message_receive);
+
+/**
+ * iucv_message_receive
+ * @path: address of iucv path structure
+ * @msg: address of iucv msg structure
+ * @flags: how the message is received (IUCV_IPBUFLST)
+ * @buffer: address of data buffer or address of struct iucv_array
+ * @size: length of data buffer
+ * @residual:
+ *
+ * This function receives messages that are being sent to you over
+ * established paths. This function will deal with RMDATA messages
+ * embedded in struct iucv_message as well.
+ *
+ * Locking:    local_bh_enable/local_bh_disable
+ *
+ * Returns the result from the CP IUCV call.
+ */
+int iucv_message_receive(struct iucv_path *path, struct iucv_message *msg,
+                        u8 flags, void *buffer, size_t size, size_t *residual)
+{
+       int rc;
+
+       if (msg->flags & IUCV_IPRMDATA)
+               return iucv_message_receive_iprmdata(path, msg, flags,
+                                                    buffer, size, residual);
+       local_bh_disable();
+       rc = __iucv_message_receive(path, msg, flags, buffer, size, residual);
        local_bh_enable();
        return rc;
 }
@@ -1038,6 +1233,10 @@ int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
        int rc;
 
        local_bh_disable();
+       if (cpus_empty(iucv_buffer_cpumask)) {
+               rc = -EIO;
+               goto out;
+       }
        parm = iucv_param[smp_processor_id()];
        memset(parm, 0, sizeof(union iucv_param));
        parm->db.ippathid = path->pathid;
@@ -1045,6 +1244,7 @@ int iucv_message_reject(struct iucv_path *path, struct iucv_message *msg)
        parm->db.iptrgcls = msg->class;
        parm->db.ipflags1 = (IUCV_IPTRGCLS | IUCV_IPFGMID | IUCV_IPFGPID);
        rc = iucv_call_b2f0(IUCV_REJECT, parm);
+out:
        local_bh_enable();
        return rc;
 }
@@ -1072,6 +1272,10 @@ int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
        int rc;
 
        local_bh_disable();
+       if (cpus_empty(iucv_buffer_cpumask)) {
+               rc = -EIO;
+               goto out;
+       }
        parm = iucv_param[smp_processor_id()];
        memset(parm, 0, sizeof(union iucv_param));
        if (flags & IUCV_IPRMDATA) {
@@ -1089,13 +1293,14 @@ int iucv_message_reply(struct iucv_path *path, struct iucv_message *msg,
                parm->db.iptrgcls = msg->class;
        }
        rc = iucv_call_b2f0(IUCV_REPLY, parm);
+out:
        local_bh_enable();
        return rc;
 }
 EXPORT_SYMBOL(iucv_message_reply);
 
 /**
- * iucv_message_send
+ * __iucv_message_send
  * @path: address of iucv path structure
  * @msg: address of iucv msg structure
  * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
@@ -1107,15 +1312,20 @@ EXPORT_SYMBOL(iucv_message_reply);
  * transmitted is in a buffer and this is a one-way message and the
  * receiver will not reply to the message.
  *
+ * Locking:    no locking
+ *
  * Returns the result from the CP IUCV call.
  */
-int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
+int __iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
                      u8 flags, u32 srccls, void *buffer, size_t size)
 {
        union iucv_param *parm;
        int rc;
 
-       local_bh_disable();
+       if (cpus_empty(iucv_buffer_cpumask)) {
+               rc = -EIO;
+               goto out;
+       }
        parm = iucv_param[smp_processor_id()];
        memset(parm, 0, sizeof(union iucv_param));
        if (flags & IUCV_IPRMDATA) {
@@ -1138,6 +1348,35 @@ int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
        rc = iucv_call_b2f0(IUCV_SEND, parm);
        if (!rc)
                msg->id = parm->db.ipmsgid;
+out:
+       return rc;
+}
+EXPORT_SYMBOL(__iucv_message_send);
+
+/**
+ * iucv_message_send
+ * @path: address of iucv path structure
+ * @msg: address of iucv msg structure
+ * @flags: how the message is sent (IUCV_IPRMDATA, IUCV_IPPRTY, IUCV_IPBUFLST)
+ * @srccls: source class of message
+ * @buffer: address of send buffer or address of struct iucv_array
+ * @size: length of send buffer
+ *
+ * This function transmits data to another application. Data to be
+ * transmitted is in a buffer and this is a one-way message and the
+ * receiver will not reply to the message.
+ *
+ * Locking:    local_bh_enable/local_bh_disable
+ *
+ * Returns the result from the CP IUCV call.
+ */
+int iucv_message_send(struct iucv_path *path, struct iucv_message *msg,
+                     u8 flags, u32 srccls, void *buffer, size_t size)
+{
+       int rc;
+
+       local_bh_disable();
+       rc = __iucv_message_send(path, msg, flags, srccls, buffer, size);
        local_bh_enable();
        return rc;
 }
@@ -1170,6 +1409,10 @@ int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
        int rc;
 
        local_bh_disable();
+       if (cpus_empty(iucv_buffer_cpumask)) {
+               rc = -EIO;
+               goto out;
+       }
        parm = iucv_param[smp_processor_id()];
        memset(parm, 0, sizeof(union iucv_param));
        if (flags & IUCV_IPRMDATA) {
@@ -1195,6 +1438,7 @@ int iucv_message_send2way(struct iucv_path *path, struct iucv_message *msg,
        rc = iucv_call_b2f0(IUCV_SEND, parm);
        if (!rc)
                msg->id = parm->db.ipmsgid;
+out:
        local_bh_enable();
        return rc;
 }
@@ -1286,6 +1530,8 @@ static void iucv_path_complete(struct iucv_irq_data *data)
        struct iucv_path_complete *ipc = (void *) data;
        struct iucv_path *path = iucv_path_table[ipc->ippathid];
 
+       if (path)
+               path->flags = ipc->ipflags1;
        if (path && path->handler && path->handler->path_complete)
                path->handler->path_complete(path, ipc->ipuser);
 }
@@ -1321,7 +1567,7 @@ static void iucv_path_severed(struct iucv_irq_data *data)
        else {
                iucv_sever_pathid(path->pathid, NULL);
                iucv_path_table[path->pathid] = NULL;
-               list_del_init(&path->list);
+               list_del(&path->list);
                iucv_path_free(path);
        }
 }
@@ -1522,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;
 
@@ -1566,7 +1811,7 @@ static void iucv_external_interrupt(u16 code)
        BUG_ON(p->iptype  < 0x01 || p->iptype > 0x09);
        work = kmalloc(sizeof(struct iucv_irq_list), GFP_ATOMIC);
        if (!work) {
-               printk(KERN_WARNING "iucv_external_interrupt: out of memory\n");
+               pr_warning("iucv_external_interrupt: out of memory\n");
                return;
        }
        memcpy(&work->data, p, sizeof(work->data));
@@ -1583,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
  *
@@ -1603,7 +1989,7 @@ static int __init iucv_init(void)
        rc = register_external_interrupt(0x4000, iucv_external_interrupt);
        if (rc)
                goto out;
-       iucv_root = s390_root_dev_register("iucv");
+       iucv_root = root_device_register("iucv");
        if (IS_ERR(iucv_root)) {
                rc = PTR_ERR(iucv_root);
                goto out_int;
@@ -1625,29 +2011,43 @@ static int __init iucv_init(void)
                        rc = -ENOMEM;
                        goto out_free;
                }
+               iucv_param_irq[cpu] = kmalloc_node(sizeof(union iucv_param),
+                                 GFP_KERNEL|GFP_DMA, cpu_to_node(cpu));
+               if (!iucv_param_irq[cpu]) {
+                       rc = -ENOMEM;
+                       goto out_free;
+               }
+
        }
        rc = register_hotcpu_notifier(&iucv_cpu_notifier);
        if (rc)
                goto out_free;
+       rc = register_reboot_notifier(&iucv_reboot_notifier);
+       if (rc)
+               goto out_cpu;
        ASCEBC(iucv_error_no_listener, 16);
        ASCEBC(iucv_error_no_memory, 16);
        ASCEBC(iucv_error_pathid, 16);
        iucv_available = 1;
        rc = bus_register(&iucv_bus);
        if (rc)
-               goto out_cpu;
+               goto out_reboot;
        return 0;
 
+out_reboot:
+       unregister_reboot_notifier(&iucv_reboot_notifier);
 out_cpu:
        unregister_hotcpu_notifier(&iucv_cpu_notifier);
 out_free:
        for_each_possible_cpu(cpu) {
+               kfree(iucv_param_irq[cpu]);
+               iucv_param_irq[cpu] = NULL;
                kfree(iucv_param[cpu]);
                iucv_param[cpu] = NULL;
                kfree(iucv_irq_data[cpu]);
                iucv_irq_data[cpu] = NULL;
        }
-       s390_root_dev_unregister(iucv_root);
+       root_device_unregister(iucv_root);
 out_int:
        unregister_external_interrupt(0x4000, iucv_external_interrupt);
 out:
@@ -1670,14 +2070,17 @@ static void __exit iucv_exit(void)
        list_for_each_entry_safe(p, n, &iucv_work_queue, list)
                kfree(p);
        spin_unlock_irq(&iucv_queue_lock);
+       unregister_reboot_notifier(&iucv_reboot_notifier);
        unregister_hotcpu_notifier(&iucv_cpu_notifier);
        for_each_possible_cpu(cpu) {
+               kfree(iucv_param_irq[cpu]);
+               iucv_param_irq[cpu] = NULL;
                kfree(iucv_param[cpu]);
                iucv_param[cpu] = NULL;
                kfree(iucv_irq_data[cpu]);
                iucv_irq_data[cpu] = NULL;
        }
-       s390_root_dev_unregister(iucv_root);
+       root_device_unregister(iucv_root);
        bus_unregister(&iucv_bus);
        unregister_external_interrupt(0x4000, iucv_external_interrupt);
 }