Merge branch 'classmate' into release
[safe/jmp/linux-2.6] / drivers / s390 / cio / device.c
index af500aa..a6c7d54 100644 (file)
@@ -314,6 +314,8 @@ static void ccw_device_unregister(struct ccw_device *cdev)
        }
 }
 
+static void io_subchannel_quiesce(struct subchannel *);
+
 /**
  * ccw_device_set_offline() - disable a ccw device for I/O
  * @cdev: target ccw device
@@ -327,7 +329,8 @@ static void ccw_device_unregister(struct ccw_device *cdev)
  */
 int ccw_device_set_offline(struct ccw_device *cdev)
 {
-       int ret;
+       struct subchannel *sch;
+       int ret, state;
 
        if (!cdev)
                return -ENODEV;
@@ -341,6 +344,7 @@ int ccw_device_set_offline(struct ccw_device *cdev)
        }
        cdev->online = 0;
        spin_lock_irq(cdev->ccwlock);
+       sch = to_subchannel(cdev->dev.parent);
        /* Wait until a final state or DISCONNECTED is reached */
        while (!dev_fsm_final_state(cdev) &&
               cdev->private->state != DEV_STATE_DISCONNECTED) {
@@ -349,9 +353,21 @@ int ccw_device_set_offline(struct ccw_device *cdev)
                           cdev->private->state == DEV_STATE_DISCONNECTED));
                spin_lock_irq(cdev->ccwlock);
        }
-       ret = ccw_device_offline(cdev);
-       if (ret)
-               goto error;
+       do {
+               ret = ccw_device_offline(cdev);
+               if (!ret)
+                       break;
+               CIO_MSG_EVENT(0, "ccw_device_offline returned %d, device "
+                             "0.%x.%04x\n", ret, cdev->private->dev_id.ssid,
+                             cdev->private->dev_id.devno);
+               if (ret != -EBUSY)
+                       goto error;
+               state = cdev->private->state;
+               spin_unlock_irq(cdev->ccwlock);
+               io_subchannel_quiesce(sch);
+               spin_lock_irq(cdev->ccwlock);
+               cdev->private->state = state;
+       } while (ret == -EBUSY);
        spin_unlock_irq(cdev->ccwlock);
        wait_event(cdev->private->wait_q, (dev_fsm_final_state(cdev) ||
                   cdev->private->state == DEV_STATE_DISCONNECTED));
@@ -368,9 +384,6 @@ int ccw_device_set_offline(struct ccw_device *cdev)
        return 0;
 
 error:
-       CIO_MSG_EVENT(0, "ccw_device_offline returned %d, device 0.%x.%04x\n",
-                     ret, cdev->private->dev_id.ssid,
-                     cdev->private->dev_id.devno);
        cdev->private->state = DEV_STATE_OFFLINE;
        dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
        spin_unlock_irq(cdev->ccwlock);
@@ -1063,16 +1076,16 @@ static int
 io_subchannel_remove (struct subchannel *sch)
 {
        struct ccw_device *cdev;
-       unsigned long flags;
 
        cdev = sch_get_cdev(sch);
        if (!cdev)
                goto out_free;
+       io_subchannel_quiesce(sch);
        /* Set ccw device to not operational and drop reference. */
-       spin_lock_irqsave(cdev->ccwlock, flags);
+       spin_lock_irq(cdev->ccwlock);
        sch_set_cdev(sch, NULL);
        cdev->private->state = DEV_STATE_NOT_OPER;
-       spin_unlock_irqrestore(cdev->ccwlock, flags);
+       spin_unlock_irq(cdev->ccwlock);
        ccw_device_unregister(cdev);
 out_free:
        kfree(sch->private);
@@ -1150,7 +1163,7 @@ static int io_subchannel_chp_event(struct subchannel *sch,
        return 0;
 }
 
-static void io_subchannel_shutdown(struct subchannel *sch)
+static void io_subchannel_quiesce(struct subchannel *sch)
 {
        struct ccw_device *cdev;
        int ret;
@@ -1182,6 +1195,11 @@ out_unlock:
        spin_unlock_irq(sch->lock);
 }
 
+static void io_subchannel_shutdown(struct subchannel *sch)
+{
+       io_subchannel_quiesce(sch);
+}
+
 static int device_is_disconnected(struct ccw_device *cdev)
 {
        if (!cdev)
@@ -1501,6 +1519,7 @@ static int ccw_device_console_enable(struct ccw_device *cdev,
        sch->driver = &io_subchannel_driver;
        /* Initialize the ccw_device structure. */
        cdev->dev.parent= &sch->dev;
+       sch_set_cdev(sch, cdev);
        io_subchannel_recog(cdev, sch);
        /* Now wait for the async. recognition to come to an end. */
        spin_lock_irq(cdev->ccwlock);
@@ -1886,7 +1905,7 @@ out_unlock:
        return ret;
 }
 
-static struct dev_pm_ops ccw_pm_ops = {
+static const struct dev_pm_ops ccw_pm_ops = {
        .prepare = ccw_device_pm_prepare,
        .complete = ccw_device_pm_complete,
        .freeze = ccw_device_pm_freeze,