From: Torsten Duwe <duwe@suse.de>
Subject: s390: zcrypt to /dev/random feeding to be resumed
Patch-mainline: not yet submitted
References: bnc#718910, fate 310591, bnc#709266, bnc#709269

The previous patch works fine unless the HW RNG is taken offline.
echo {0,1} > /sys/devices/ap/card05/online now allows the operator to relaunch
the feeder thread once the hardware is back online.

Signed-off-by: Torsten Duwe <duwe@suse.de>
Acked-by: Torsten Duwe <duwe@suse.de>

---
 zcrypt_api.c |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
--- linux-3.0-SLE11-SP2/drivers/s390/crypto/zcrypt_api.c.orig	2012-07-10 15:00:33.306872776 +0200
+++ linux-3.0-SLE11-SP2/drivers/s390/crypto/zcrypt_api.c	2012-07-10 16:46:32.442016477 +0200
@@ -88,6 +88,15 @@ static ssize_t zcrypt_online_store(struc
 
 	if (sscanf(buf, "%d\n", &online) != 1 || online < 0 || online > 1)
 		return -EINVAL;
+	if (zdev->ops->rng) {
+		if (zdev->online == 0 && online == 1) {
+               		zcrypt_rng_device_add();
+		}
+		if (zdev->online == 1 && online == 0) {
+			zcrypt_rng_device_remove();
+		}
+
+	}
 	zdev->online = online;
 	if (!online)
 		ap_flush_queue(zdev->ap_dev);
@@ -1211,8 +1220,10 @@ static void zcrypt_rng_device_remove(voi
 	mutex_lock(&zcrypt_rng_mutex);
 	zcrypt_rng_device_count--;
 	if (zcrypt_rng_device_count == 0) {
-		if (zcrypt_hwrng_fill)
+		if (zcrypt_hwrng_fill) {
 			kthread_stop(zcrypt_hwrng_fill);
+			zcrypt_hwrng_fill = 0;
+		}
 		hwrng_unregister(&zcrypt_rng_dev);
 		free_page((unsigned long) zcrypt_rng_buffer);
 	}
