Merge branch 'for-rmk/samsung6' of git://git.fluff.org/bjdooks/linux into devel-stable
[linux-2.6.git] / drivers / s390 / block / dasd.c
index e64f62d..5905936 100644 (file)
@@ -5,8 +5,7 @@
  *                 Carsten Otte <Cotte@de.ibm.com>
  *                 Martin Schwidefsky <schwidefsky@de.ibm.com>
  * Bugreports.to..: <Linux390@de.ibm.com>
- * (C) IBM Corporation, IBM Deutschland Entwicklung GmbH, 1999-2001
- *
+ * Copyright IBM Corp. 1999, 2009
  */
 
 #define KMSG_COMPONENT "dasd"
@@ -25,7 +24,6 @@
 #include <asm/ccwdev.h>
 #include <asm/ebcdic.h>
 #include <asm/idals.h>
-#include <asm/todclk.h>
 #include <asm/itcw.h>
 
 /* This is ugly... */
@@ -61,9 +59,11 @@ static int dasd_flush_block_queue(struct dasd_block *);
 static void dasd_device_tasklet(struct dasd_device *);
 static void dasd_block_tasklet(struct dasd_block *);
 static void do_kick_device(struct work_struct *);
+static void do_restore_device(struct work_struct *);
 static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *);
 static void dasd_device_timeout(unsigned long);
 static void dasd_block_timeout(unsigned long);
+static void __dasd_process_erp(struct dasd_device *, struct dasd_ccw_req *);
 
 /*
  * SECTION: Operations on the device structure.
@@ -109,6 +109,7 @@ struct dasd_device *dasd_alloc_device(void)
        device->timer.function = dasd_device_timeout;
        device->timer.data = (unsigned long) device;
        INIT_WORK(&device->kick_work, do_kick_device);
+       INIT_WORK(&device->restore_device, do_restore_device);
        device->state = DASD_STATE_NEW;
        device->target = DASD_STATE_NEW;
 
@@ -469,7 +470,7 @@ static int dasd_decrease_state(struct dasd_device *device)
  */
 static void dasd_change_state(struct dasd_device *device)
 {
-        int rc;
+       int rc;
 
        if (device->state == device->target)
                /* Already where we want to go today... */
@@ -478,8 +479,10 @@ static void dasd_change_state(struct dasd_device *device)
                rc = dasd_increase_state(device);
        else
                rc = dasd_decrease_state(device);
-        if (rc && rc != -EAGAIN)
-                device->target = device->state;
+       if (rc == -EAGAIN)
+               return;
+       if (rc)
+               device->target = device->state;
 
        if (device->state == device->target) {
                wake_up(&dasd_init_waitq);
@@ -512,6 +515,25 @@ void dasd_kick_device(struct dasd_device *device)
 }
 
 /*
+ * dasd_restore_device will schedule a call do do_restore_device to the kernel
+ * event daemon.
+ */
+static void do_restore_device(struct work_struct *work)
+{
+       struct dasd_device *device = container_of(work, struct dasd_device,
+                                                 restore_device);
+       device->cdev->drv->restore(device->cdev);
+       dasd_put_device(device);
+}
+
+void dasd_restore_device(struct dasd_device *device)
+{
+       dasd_get_device(device);
+       /* queue call to dasd_restore_device to the kernel event daemon. */
+       schedule_work(&device->restore_device);
+}
+
+/*
  * Set the target state for a device and starts the state change.
  */
 void dasd_set_target_state(struct dasd_device *device, int target)
@@ -647,14 +669,14 @@ static void dasd_profile_end(struct dasd_block *block,
  * memory and 2) dasd_smalloc_request uses the static ccw memory
  * that gets allocated for each device.
  */
-struct dasd_ccw_req *dasd_kmalloc_request(char *magic, int cplength,
+struct dasd_ccw_req *dasd_kmalloc_request(int magic, int cplength,
                                          int datasize,
                                          struct dasd_device *device)
 {
        struct dasd_ccw_req *cqr;
 
        /* Sanity checks */
-       BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
+       BUG_ON(datasize > PAGE_SIZE ||
             (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
 
        cqr = kzalloc(sizeof(struct dasd_ccw_req), GFP_ATOMIC);
@@ -678,14 +700,13 @@ struct dasd_ccw_req *dasd_kmalloc_request(char *magic, int cplength,
                        return ERR_PTR(-ENOMEM);
                }
        }
-       strncpy((char *) &cqr->magic, magic, 4);
-       ASCEBC((char *) &cqr->magic, 4);
+       cqr->magic =  magic;
        set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
        dasd_get_device(device);
        return cqr;
 }
 
-struct dasd_ccw_req *dasd_smalloc_request(char *magic, int cplength,
+struct dasd_ccw_req *dasd_smalloc_request(int magic, int cplength,
                                          int datasize,
                                          struct dasd_device *device)
 {
@@ -695,7 +716,7 @@ struct dasd_ccw_req *dasd_smalloc_request(char *magic, int cplength,
        int size;
 
        /* Sanity checks */
-       BUG_ON( magic == NULL || datasize > PAGE_SIZE ||
+       BUG_ON(datasize > PAGE_SIZE ||
             (cplength*sizeof(struct ccw1)) > PAGE_SIZE);
 
        size = (sizeof(struct dasd_ccw_req) + 7L) & -8L;
@@ -722,8 +743,7 @@ struct dasd_ccw_req *dasd_smalloc_request(char *magic, int cplength,
                cqr->data = data;
                memset(cqr->data, 0, datasize);
        }
-       strncpy((char *) &cqr->magic, magic, 4);
-       ASCEBC((char *) &cqr->magic, 4);
+       cqr->magic = magic;
        set_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
        dasd_get_device(device);
        return cqr;
@@ -851,8 +871,10 @@ int dasd_start_IO(struct dasd_ccw_req *cqr)
 
        /* Check the cqr */
        rc = dasd_check_cqr(cqr);
-       if (rc)
+       if (rc) {
+               cqr->intrc = rc;
                return rc;
+       }
        device = (struct dasd_device *) cqr->startdev;
        if (cqr->retries < 0) {
                /* internal error 14 - start_IO run out of retries */
@@ -875,9 +897,6 @@ int dasd_start_IO(struct dasd_ccw_req *cqr)
        switch (rc) {
        case 0:
                cqr->status = DASD_CQR_IN_IO;
-               DBF_DEV_EVENT(DBF_DEBUG, device,
-                             "start_IO: request %p started successful",
-                             cqr);
                break;
        case -EBUSY:
                DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
@@ -906,6 +925,12 @@ int dasd_start_IO(struct dasd_ccw_req *cqr)
                DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
                              "start_IO: -EIO device gone, retry");
                break;
+       case -EINVAL:
+               /* most likely caused in power management context */
+               DBF_DEV_EVENT(DBF_DEBUG, device, "%s",
+                             "start_IO: -EINVAL device currently "
+                             "not accessible");
+               break;
        default:
                /* internal error 11 - unknown rc */
                snprintf(errorstring, ERRORLENGTH, "11 %d", rc);
@@ -915,6 +940,7 @@ int dasd_start_IO(struct dasd_ccw_req *cqr)
                BUG();
                break;
        }
+       cqr->intrc = rc;
        return rc;
 }
 
@@ -934,7 +960,7 @@ static void dasd_device_timeout(unsigned long ptr)
        device = (struct dasd_device *) ptr;
        spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
        /* re-activate request queue */
-        device->stopped &= ~DASD_STOPPED_PENDING;
+       dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
        spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
        dasd_schedule_device_bh(device);
 }
@@ -968,10 +994,9 @@ static void dasd_handle_killed_request(struct ccw_device *cdev,
                return;
        cqr = (struct dasd_ccw_req *) intparm;
        if (cqr->status != DASD_CQR_IN_IO) {
-               DBF_EVENT(DBF_DEBUG,
-                       "invalid status in handle_killed_request: "
-                       "bus_id %s, status %02x",
-                       dev_name(&cdev->dev), cqr->status);
+               DBF_EVENT_DEVID(DBF_DEBUG, cdev,
+                               "invalid status in handle_killed_request: "
+                               "%02x", cqr->status);
                return;
        }
 
@@ -979,8 +1004,8 @@ static void dasd_handle_killed_request(struct ccw_device *cdev,
        if (device == NULL ||
            device != dasd_device_from_cdev_locked(cdev) ||
            strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
-               DBF_DEV_EVENT(DBF_DEBUG, device, "invalid device in request: "
-                             "bus_id %s", dev_name(&cdev->dev));
+               DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
+                               "invalid device in request");
                return;
        }
 
@@ -997,7 +1022,7 @@ void dasd_generic_handle_state_change(struct dasd_device *device)
        /* First of all start sense subsystem status request. */
        dasd_eer_snss(device);
 
-       device->stopped &= ~DASD_STOPPED_PENDING;
+       dasd_device_remove_stop_bits(device, DASD_STOPPED_PENDING);
        dasd_schedule_device_bh(device);
        if (device->block)
                dasd_schedule_block_bh(device->block);
@@ -1019,12 +1044,13 @@ void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
                case -EIO:
                        break;
                case -ETIMEDOUT:
-                       DBF_EVENT(DBF_WARNING, "%s(%s): request timed out\n",
-                              __func__, dev_name(&cdev->dev));
+                       DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
+                                       "request timed out\n", __func__);
                        break;
                default:
-                       DBF_EVENT(DBF_WARNING, "%s(%s): unknown error %ld\n",
-                              __func__, dev_name(&cdev->dev), PTR_ERR(irb));
+                       DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s: "
+                                       "unknown error %ld\n", __func__,
+                                       PTR_ERR(irb));
                }
                dasd_handle_killed_request(cdev, intparm);
                return;
@@ -1052,8 +1078,8 @@ void dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
        device = (struct dasd_device *) cqr->startdev;
        if (!device ||
            strncmp(device->discipline->ebcname, (char *) &cqr->magic, 4)) {
-               DBF_DEV_EVENT(DBF_DEBUG, device, "invalid device in request: "
-                             "bus_id %s", dev_name(&cdev->dev));
+               DBF_EVENT_DEVID(DBF_DEBUG, cdev, "%s",
+                               "invalid device in request");
                return;
        }
 
@@ -1379,6 +1405,20 @@ void dasd_schedule_device_bh(struct dasd_device *device)
        tasklet_hi_schedule(&device->tasklet);
 }
 
+void dasd_device_set_stop_bits(struct dasd_device *device, int bits)
+{
+       device->stopped |= bits;
+}
+EXPORT_SYMBOL_GPL(dasd_device_set_stop_bits);
+
+void dasd_device_remove_stop_bits(struct dasd_device *device, int bits)
+{
+       device->stopped &= ~bits;
+       if (!device->stopped)
+               wake_up(&generic_waitq);
+}
+EXPORT_SYMBOL_GPL(dasd_device_remove_stop_bits);
+
 /*
  * Queue a request to the head of the device ccw_queue.
  * Start the I/O if possible.
@@ -1439,47 +1479,135 @@ static inline int _wait_for_wakeup(struct dasd_ccw_req *cqr)
 }
 
 /*
- * Queue a request to the tail of the device ccw_queue and wait for
- * it's completion.
+ * checks if error recovery is necessary, returns 1 if yes, 0 otherwise.
  */
-int dasd_sleep_on(struct dasd_ccw_req *cqr)
+static int __dasd_sleep_on_erp(struct dasd_ccw_req *cqr)
 {
        struct dasd_device *device;
-       int rc;
+       dasd_erp_fn_t erp_fn;
 
+       if (cqr->status == DASD_CQR_FILLED)
+               return 0;
        device = cqr->startdev;
+       if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
+               if (cqr->status == DASD_CQR_TERMINATED) {
+                       device->discipline->handle_terminated_request(cqr);
+                       return 1;
+               }
+               if (cqr->status == DASD_CQR_NEED_ERP) {
+                       erp_fn = device->discipline->erp_action(cqr);
+                       erp_fn(cqr);
+                       return 1;
+               }
+               if (cqr->status == DASD_CQR_FAILED)
+                       dasd_log_sense(cqr, &cqr->irb);
+               if (cqr->refers) {
+                       __dasd_process_erp(device, cqr);
+                       return 1;
+               }
+       }
+       return 0;
+}
 
-       cqr->callback = dasd_wakeup_cb;
-       cqr->callback_data = (void *) &generic_waitq;
-       dasd_add_request_tail(cqr);
-       wait_event(generic_waitq, _wait_for_wakeup(cqr));
+static int __dasd_sleep_on_loop_condition(struct dasd_ccw_req *cqr)
+{
+       if (test_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags)) {
+               if (cqr->refers) /* erp is not done yet */
+                       return 1;
+               return ((cqr->status != DASD_CQR_DONE) &&
+                       (cqr->status != DASD_CQR_FAILED));
+       } else
+               return (cqr->status == DASD_CQR_FILLED);
+}
+
+static int _dasd_sleep_on(struct dasd_ccw_req *maincqr, int interruptible)
+{
+       struct dasd_device *device;
+       int rc;
+       struct list_head ccw_queue;
+       struct dasd_ccw_req *cqr;
+
+       INIT_LIST_HEAD(&ccw_queue);
+       maincqr->status = DASD_CQR_FILLED;
+       device = maincqr->startdev;
+       list_add(&maincqr->blocklist, &ccw_queue);
+       for (cqr = maincqr;  __dasd_sleep_on_loop_condition(cqr);
+            cqr = list_first_entry(&ccw_queue,
+                                   struct dasd_ccw_req, blocklist)) {
+
+               if (__dasd_sleep_on_erp(cqr))
+                       continue;
+               if (cqr->status != DASD_CQR_FILLED) /* could be failed */
+                       continue;
 
-       /* Request status is either done or failed. */
-       rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
+               /* Non-temporary stop condition will trigger fail fast */
+               if (device->stopped & ~DASD_STOPPED_PENDING &&
+                   test_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags) &&
+                   (!dasd_eer_enabled(device))) {
+                       cqr->status = DASD_CQR_FAILED;
+                       continue;
+               }
+
+               /* Don't try to start requests if device is stopped */
+               if (interruptible) {
+                       rc = wait_event_interruptible(
+                               generic_waitq, !(device->stopped));
+                       if (rc == -ERESTARTSYS) {
+                               cqr->status = DASD_CQR_FAILED;
+                               maincqr->intrc = rc;
+                               continue;
+                       }
+               } else
+                       wait_event(generic_waitq, !(device->stopped));
+
+               cqr->callback = dasd_wakeup_cb;
+               cqr->callback_data = (void *) &generic_waitq;
+               dasd_add_request_tail(cqr);
+               if (interruptible) {
+                       rc = wait_event_interruptible(
+                               generic_waitq, _wait_for_wakeup(cqr));
+                       if (rc == -ERESTARTSYS) {
+                               dasd_cancel_req(cqr);
+                               /* wait (non-interruptible) for final status */
+                               wait_event(generic_waitq,
+                                          _wait_for_wakeup(cqr));
+                               cqr->status = DASD_CQR_FAILED;
+                               maincqr->intrc = rc;
+                               continue;
+                       }
+               } else
+                       wait_event(generic_waitq, _wait_for_wakeup(cqr));
+       }
+
+       maincqr->endclk = get_clock();
+       if ((maincqr->status != DASD_CQR_DONE) &&
+           (maincqr->intrc != -ERESTARTSYS))
+               dasd_log_sense(maincqr, &maincqr->irb);
+       if (maincqr->status == DASD_CQR_DONE)
+               rc = 0;
+       else if (maincqr->intrc)
+               rc = maincqr->intrc;
+       else
+               rc = -EIO;
        return rc;
 }
 
 /*
+ * Queue a request to the tail of the device ccw_queue and wait for
+ * it's completion.
+ */
+int dasd_sleep_on(struct dasd_ccw_req *cqr)
+{
+       return _dasd_sleep_on(cqr, 0);
+}
+
+/*
  * Queue a request to the tail of the device ccw_queue and wait
  * interruptible for it's completion.
  */
 int dasd_sleep_on_interruptible(struct dasd_ccw_req *cqr)
 {
-       struct dasd_device *device;
-       int rc;
-
-       device = cqr->startdev;
-       cqr->callback = dasd_wakeup_cb;
-       cqr->callback_data = (void *) &generic_waitq;
-       dasd_add_request_tail(cqr);
-       rc = wait_event_interruptible(generic_waitq, _wait_for_wakeup(cqr));
-       if (rc == -ERESTARTSYS) {
-               dasd_cancel_req(cqr);
-               /* wait (non-interruptible) for final status */
-               wait_event(generic_waitq, _wait_for_wakeup(cqr));
-       }
-       rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
-       return rc;
+       return _dasd_sleep_on(cqr, 1);
 }
 
 /*
@@ -1523,8 +1651,12 @@ int dasd_sleep_on_immediatly(struct dasd_ccw_req *cqr)
 
        wait_event(generic_waitq, _wait_for_wakeup(cqr));
 
-       /* Request status is either done or failed. */
-       rc = (cqr->status == DASD_CQR_DONE) ? 0 : -EIO;
+       if (cqr->status == DASD_CQR_DONE)
+               rc = 0;
+       else if (cqr->intrc)
+               rc = cqr->intrc;
+       else
+               rc = -EIO;
        return rc;
 }
 
@@ -1589,7 +1721,7 @@ static void dasd_block_timeout(unsigned long ptr)
        block = (struct dasd_block *) ptr;
        spin_lock_irqsave(get_ccwdev_lock(block->base->cdev), flags);
        /* re-activate request queue */
-       block->base->stopped &= ~DASD_STOPPED_PENDING;
+       dasd_device_remove_stop_bits(block->base, DASD_STOPPED_PENDING);
        spin_unlock_irqrestore(get_ccwdev_lock(block->base->cdev), flags);
        dasd_schedule_block_bh(block);
 }
@@ -1616,11 +1748,10 @@ void dasd_block_clear_timer(struct dasd_block *block)
 /*
  * Process finished error recovery ccw.
  */
-static inline void __dasd_block_process_erp(struct dasd_block *block,
-                                           struct dasd_ccw_req *cqr)
+static void __dasd_process_erp(struct dasd_device *device,
+                              struct dasd_ccw_req *cqr)
 {
        dasd_erp_fn_t erp_fn;
-       struct dasd_device *device = block->base;
 
        if (cqr->status == DASD_CQR_DONE)
                DBF_DEV_EVENT(DBF_NOTICE, device, "%s", "ERP successful");
@@ -1653,8 +1784,11 @@ static void __dasd_process_request_queue(struct dasd_block *block)
         * for that. State DASD_STATE_ONLINE is normal block device
         * operation.
         */
-       if (basedev->state < DASD_STATE_READY)
+       if (basedev->state < DASD_STATE_READY) {
+               while ((req = blk_fetch_request(block->request_queue)))
+                       __blk_end_request_all(req, -EIO);
                return;
+       }
        /* Now we try to fetch requests from the request queue */
        while (!blk_queue_plugged(queue) && (req = blk_peek_request(queue))) {
                if (basedev->features & DASD_FEATURE_READONLY &&
@@ -1681,9 +1815,12 @@ static void __dasd_process_request_queue(struct dasd_block *block)
                                 */
                                if (!list_empty(&block->ccw_queue))
                                        break;
-                               spin_lock_irqsave(get_ccwdev_lock(basedev->cdev), flags);
-                               basedev->stopped |= DASD_STOPPED_PENDING;
-                               spin_unlock_irqrestore(get_ccwdev_lock(basedev->cdev), flags);
+                               spin_lock_irqsave(
+                                       get_ccwdev_lock(basedev->cdev), flags);
+                               dasd_device_set_stop_bits(basedev,
+                                                         DASD_STOPPED_PENDING);
+                               spin_unlock_irqrestore(
+                                       get_ccwdev_lock(basedev->cdev), flags);
                                dasd_block_set_timer(block, HZ/2);
                                break;
                        }
@@ -1769,7 +1906,7 @@ restart:
                        cqr->status = DASD_CQR_FILLED;
                        cqr->retries = 255;
                        spin_lock_irqsave(get_ccwdev_lock(base->cdev), flags);
-                       base->stopped |= DASD_STOPPED_QUIESCE;
+                       dasd_device_set_stop_bits(base, DASD_STOPPED_QUIESCE);
                        spin_unlock_irqrestore(get_ccwdev_lock(base->cdev),
                                               flags);
                        goto restart;
@@ -1777,7 +1914,7 @@ restart:
 
                /* Process finished ERP request. */
                if (cqr->refers) {
-                       __dasd_block_process_erp(block, cqr);
+                       __dasd_process_erp(base, cqr);
                        goto restart;
                }
 
@@ -1908,7 +2045,7 @@ restart_cb:
                /* Process finished ERP request. */
                if (cqr->refers) {
                        spin_lock_bh(&block->queue_lock);
-                       __dasd_block_process_erp(block, cqr);
+                       __dasd_process_erp(block->base, cqr);
                        spin_unlock_bh(&block->queue_lock);
                        /* restart list_for_xx loop since dasd_process_erp
                         * might remove multiple elements */
@@ -1990,7 +2127,7 @@ static void dasd_setup_queue(struct dasd_block *block)
 {
        int max;
 
-       blk_queue_hardsect_size(block->request_queue, block->bp_block);
+       blk_queue_logical_block_size(block->request_queue, block->bp_block);
        max = block->base->discipline->max_blocks << block->s2b_shift;
        blk_queue_max_sectors(block->request_queue, max);
        blk_queue_max_phys_segments(block->request_queue, -1L);
@@ -2089,9 +2226,9 @@ static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
        struct dasd_device *base;
 
        block = bdev->bd_disk->private_data;
-       base = block->base;
        if (!block)
                return -ENODEV;
+       base = block->base;
 
        if (!base->discipline ||
            !base->discipline->fill_geometry)
@@ -2102,7 +2239,7 @@ static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
        return 0;
 }
 
-struct block_device_operations
+const struct block_device_operations
 dasd_device_operations = {
        .owner          = THIS_MODULE,
        .open           = dasd_open,
@@ -2164,18 +2301,11 @@ int dasd_generic_probe(struct ccw_device *cdev,
 {
        int ret;
 
-       ret = ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP);
-       if (ret) {
-               DBF_EVENT(DBF_WARNING,
-                      "dasd_generic_probe: could not set ccw-device options "
-                      "for %s\n", dev_name(&cdev->dev));
-               return ret;
-       }
        ret = dasd_add_sysfs_files(cdev);
        if (ret) {
-               DBF_EVENT(DBF_WARNING,
-                      "dasd_generic_probe: could not add sysfs entries "
-                      "for %s\n", dev_name(&cdev->dev));
+               DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
+                               "dasd_generic_probe: could not add "
+                               "sysfs entries");
                return ret;
        }
        cdev->handler = &dasd_int_handler;
@@ -2374,14 +2504,20 @@ int dasd_generic_notify(struct ccw_device *cdev, int event)
                                cqr->status = DASD_CQR_QUEUED;
                                cqr->retries++;
                        }
-               device->stopped |= DASD_STOPPED_DC_WAIT;
+               dasd_device_set_stop_bits(device, DASD_STOPPED_DC_WAIT);
                dasd_device_clear_timer(device);
                dasd_schedule_device_bh(device);
                ret = 1;
                break;
        case CIO_OPER:
                /* FIXME: add a sanity check. */
-               device->stopped &= ~DASD_STOPPED_DC_WAIT;
+               dasd_device_remove_stop_bits(device, DASD_STOPPED_DC_WAIT);
+               if (device->stopped & DASD_UNRESUMED_PM) {
+                       dasd_device_remove_stop_bits(device, DASD_UNRESUMED_PM);
+                       dasd_restore_device(device);
+                       ret = 1;
+                       break;
+               }
                dasd_schedule_device_bh(device);
                if (device->block)
                        dasd_schedule_block_bh(device->block);
@@ -2392,13 +2528,102 @@ int dasd_generic_notify(struct ccw_device *cdev, int event)
        return ret;
 }
 
+int dasd_generic_pm_freeze(struct ccw_device *cdev)
+{
+       struct dasd_ccw_req *cqr, *n;
+       int rc;
+       struct list_head freeze_queue;
+       struct dasd_device *device = dasd_device_from_cdev(cdev);
+
+       if (IS_ERR(device))
+               return PTR_ERR(device);
+       /* disallow new I/O  */
+       dasd_device_set_stop_bits(device, DASD_STOPPED_PM);
+       /* clear active requests */
+       INIT_LIST_HEAD(&freeze_queue);
+       spin_lock_irq(get_ccwdev_lock(cdev));
+       rc = 0;
+       list_for_each_entry_safe(cqr, n, &device->ccw_queue, devlist) {
+               /* Check status and move request to flush_queue */
+               if (cqr->status == DASD_CQR_IN_IO) {
+                       rc = device->discipline->term_IO(cqr);
+                       if (rc) {
+                               /* unable to terminate requeust */
+                               dev_err(&device->cdev->dev,
+                                       "Unable to terminate request %p "
+                                       "on suspend\n", cqr);
+                               spin_unlock_irq(get_ccwdev_lock(cdev));
+                               dasd_put_device(device);
+                               return rc;
+                       }
+               }
+               list_move_tail(&cqr->devlist, &freeze_queue);
+       }
+
+       spin_unlock_irq(get_ccwdev_lock(cdev));
+
+       list_for_each_entry_safe(cqr, n, &freeze_queue, devlist) {
+               wait_event(dasd_flush_wq,
+                          (cqr->status != DASD_CQR_CLEAR_PENDING));
+               if (cqr->status == DASD_CQR_CLEARED)
+                       cqr->status = DASD_CQR_QUEUED;
+       }
+       /* move freeze_queue to start of the ccw_queue */
+       spin_lock_irq(get_ccwdev_lock(cdev));
+       list_splice_tail(&freeze_queue, &device->ccw_queue);
+       spin_unlock_irq(get_ccwdev_lock(cdev));
+
+       if (device->discipline->freeze)
+               rc = device->discipline->freeze(device);
+
+       dasd_put_device(device);
+       return rc;
+}
+EXPORT_SYMBOL_GPL(dasd_generic_pm_freeze);
+
+int dasd_generic_restore_device(struct ccw_device *cdev)
+{
+       struct dasd_device *device = dasd_device_from_cdev(cdev);
+       int rc = 0;
+
+       if (IS_ERR(device))
+               return PTR_ERR(device);
+
+       /* allow new IO again */
+       dasd_device_remove_stop_bits(device,
+                                    (DASD_STOPPED_PM | DASD_UNRESUMED_PM));
+
+       dasd_schedule_device_bh(device);
+
+       /*
+        * call discipline restore function
+        * if device is stopped do nothing e.g. for disconnected devices
+        */
+       if (device->discipline->restore && !(device->stopped))
+               rc = device->discipline->restore(device);
+       if (rc || device->stopped)
+               /*
+                * if the resume failed for the DASD we put it in
+                * an UNRESUMED stop state
+                */
+               device->stopped |= DASD_UNRESUMED_PM;
+
+       if (device->block)
+               dasd_schedule_block_bh(device->block);
+
+       dasd_put_device(device);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(dasd_generic_restore_device);
+
 static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
                                                   void *rdc_buffer,
                                                   int rdc_buffer_size,
-                                                  char *magic)
+                                                  int magic)
 {
        struct dasd_ccw_req *cqr;
        struct ccw1 *ccw;
+       unsigned long *idaw;
 
        cqr = dasd_smalloc_request(magic, 1 /* RDC */, rdc_buffer_size, device);
 
@@ -2412,27 +2637,34 @@ static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
 
        ccw = cqr->cpaddr;
        ccw->cmd_code = CCW_CMD_RDC;
-       ccw->cda = (__u32)(addr_t)rdc_buffer;
-       ccw->count = rdc_buffer_size;
+       if (idal_is_needed(rdc_buffer, rdc_buffer_size)) {
+               idaw = (unsigned long *) (cqr->data);
+               ccw->cda = (__u32)(addr_t) idaw;
+               ccw->flags = CCW_FLAG_IDA;
+               idaw = idal_create_words(idaw, rdc_buffer, rdc_buffer_size);
+       } else {
+               ccw->cda = (__u32)(addr_t) rdc_buffer;
+               ccw->flags = 0;
+       }
 
+       ccw->count = rdc_buffer_size;
        cqr->startdev = device;
        cqr->memdev = device;
        cqr->expires = 10*HZ;
-       clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
-       cqr->retries = 2;
+       cqr->retries = 256;
        cqr->buildclk = get_clock();
        cqr->status = DASD_CQR_FILLED;
        return cqr;
 }
 
 
-int dasd_generic_read_dev_chars(struct dasd_device *device, char *magic,
-                               void **rdc_buffer, int rdc_buffer_size)
+int dasd_generic_read_dev_chars(struct dasd_device *device, int magic,
+                               void *rdc_buffer, int rdc_buffer_size)
 {
        int ret;
        struct dasd_ccw_req *cqr;
 
-       cqr = dasd_generic_build_rdc(device, *rdc_buffer, rdc_buffer_size,
+       cqr = dasd_generic_build_rdc(device, rdc_buffer, rdc_buffer_size,
                                     magic);
        if (IS_ERR(cqr))
                return PTR_ERR(cqr);