From 583b4799f1caa8726a09089c0b5597aa7570c402 Mon Sep 17 00:00:00 2001
From: Nikos Mavrogiannopoulos <nmav@gnutls.org>
Date: Mon, 4 Mar 2013 04:56:42 +0100
Subject: [PATCH 240/291] cryptodev: async

---
 drivers/staging/crypto/cryptodev/Makefile             | 12 +++++++++---
 drivers/staging/crypto/cryptodev/NEWS                 |  5 ++++-
 drivers/staging/crypto/cryptodev/crypto/cryptodev.h   | 10 ++++++----
 drivers/staging/crypto/cryptodev/ioctl.c              |  7 ++++++-
 drivers/staging/crypto/cryptodev/tests/Makefile       |  4 ++--
 drivers/staging/crypto/cryptodev/tests/async_cipher.c | 10 +++++++++-
 drivers/staging/crypto/cryptodev/tests/async_hmac.c   |  9 +++++++++
 drivers/staging/crypto/cryptodev/tests/async_speed.c  | 10 ++++++++++
 8 files changed, 55 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/crypto/cryptodev/Makefile b/drivers/staging/crypto/cryptodev/Makefile
index 40d784a411e7..d66ef26be8b5 100644
--- a/drivers/staging/crypto/cryptodev/Makefile
+++ b/drivers/staging/crypto/cryptodev/Makefile
@@ -1,4 +1,10 @@
-KBUILD_CFLAGS += -I$(src)
+#
+# Since version 1.6 the asynchronous mode has been
+# disabled by default. To re-enable it uncomment the
+# corresponding CFLAG.
+#
+CRYPTODEV_CFLAGS ?= #-DENABLE_ASYNC
+KBUILD_CFLAGS += -I$(src) $(CRYPTODEV_CFLAGS)
 KERNEL_DIR = /lib/modules/$(shell uname -r)/build
 VERSION = 1.6
 PREFIX =
@@ -23,10 +29,10 @@ modules_install:
 clean:
 	make -C $(KERNEL_DIR) SUBDIRS=`pwd` clean
 	rm -f $(hostprogs) *~
-	KERNEL_DIR=$(KERNEL_DIR) make -C tests clean
+	CFLAGS=$(CRYPTODEV_CFLAGS) KERNEL_DIR=$(KERNEL_DIR) make -C tests clean
 
 check:
-	KERNEL_DIR=$(KERNEL_DIR) make -C tests check
+	CFLAGS=$(CRYPTODEV_CFLAGS) KERNEL_DIR=$(KERNEL_DIR) make -C tests check
 
 FILEBASE = cryptodev-linux-$(VERSION)
 TMPDIR ?= /tmp
diff --git a/drivers/staging/crypto/cryptodev/NEWS b/drivers/staging/crypto/cryptodev/NEWS
index b04065f91667..9706613fa7b8 100644
--- a/drivers/staging/crypto/cryptodev/NEWS
+++ b/drivers/staging/crypto/cryptodev/NEWS
@@ -2,10 +2,13 @@ Version 1.6 (unreleased)
 
 * Added modules_install target in Makefile
 
+* Added SHA224. Patch by Yashpal Dutta.
+
 * Asynchronous operations will not be scheduled if zero
 copy is disabled.
 
-* Added SHA224. Patch by Yashpal Dutta.
+* Asynchronous operations are disabled by default, unless
+-DENABLE_ASYNC is enabled on Makefile.
 
 
 Version 1.5 (released 2012-08-04)
diff --git a/drivers/staging/crypto/cryptodev/crypto/cryptodev.h b/drivers/staging/crypto/cryptodev/crypto/cryptodev.h
index 6382d4325f0f..a2f11b11d1aa 100644
--- a/drivers/staging/crypto/cryptodev/crypto/cryptodev.h
+++ b/drivers/staging/crypto/cryptodev/crypto/cryptodev.h
@@ -280,11 +280,13 @@ enum cryptodev_crk_op_t {
  */
 #define CRIOGET_NOT_NEEDED 1
 
-/* additional ioctls for asynchronous  operation */
-#define CIOCASYNCCRYPT    _IOW('c', 107, struct crypt_op)
-#define CIOCASYNCFETCH    _IOR('c', 108, struct crypt_op)
-
 /* additional ioctls for AEAD */
 #define CIOCAUTHCRYPT   _IOWR('c', 109, struct crypt_auth_op)
 
+/* additional ioctls for asynchronous operation.
+ * These are conditionally enabled since version 1.6.
+ */
+#define CIOCASYNCCRYPT    _IOW('c', 110, struct crypt_op)
+#define CIOCASYNCFETCH    _IOR('c', 111, struct crypt_op)
+
 #endif /* L_CRYPTODEV_H */
diff --git a/drivers/staging/crypto/cryptodev/ioctl.c b/drivers/staging/crypto/cryptodev/ioctl.c
index 6d1ae25088f8..f26cf934e97f 100644
--- a/drivers/staging/crypto/cryptodev/ioctl.c
+++ b/drivers/staging/crypto/cryptodev/ioctl.c
@@ -538,6 +538,7 @@ clonefd(struct file *filp)
 	return ret;
 }
 
+#ifdef ENABLE_ASYNC
 /* enqueue a job for asynchronous completion
  *
  * returns:
@@ -615,6 +616,7 @@ static int crypto_async_fetch(struct crypt_priv *pcr,
 
 	return retval;
 }
+#endif
 
 /* this function has to be called from process context */
 static int fill_kcop_from_cop(struct kernel_crypt_op *kcop, struct fcrypt *fcr)
@@ -867,6 +869,7 @@ cryptodev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg_)
 			return ret;
 		}
 		return kcaop_to_user(&kcaop, fcr, arg);
+#ifdef ENABLE_ASYNC
 	case CIOCASYNCCRYPT:
 		if (unlikely(ret = kcop_from_user(&kcop, fcr, arg)))
 			return ret;
@@ -878,6 +881,7 @@ cryptodev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg_)
 			return ret;
 
 		return kcop_to_user(&kcop, fcr, arg);
+#endif
 	default:
 		return -EINVAL;
 	}
@@ -1023,6 +1027,7 @@ cryptodev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg_)
 			return ret;
 
 		return compat_kcop_to_user(&kcop, fcr, arg);
+#ifdef ENABLE_ASYNC
 	case COMPAT_CIOCASYNCCRYPT:
 		if (unlikely(ret = compat_kcop_from_user(&kcop, fcr, arg)))
 			return ret;
@@ -1034,7 +1039,7 @@ cryptodev_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg_)
 			return ret;
 
 		return compat_kcop_to_user(&kcop, fcr, arg);
-
+#endif
 	default:
 		return -EINVAL;
 	}
diff --git a/drivers/staging/crypto/cryptodev/tests/Makefile b/drivers/staging/crypto/cryptodev/tests/Makefile
index 87ca3c7b46cb..c9f04e820fee 100644
--- a/drivers/staging/crypto/cryptodev/tests/Makefile
+++ b/drivers/staging/crypto/cryptodev/tests/Makefile
@@ -1,6 +1,6 @@
 KERNEL_DIR ?= /lib/modules/$(shell uname -r)/build
-KBUILD_CFLAGS += -I..
-CFLAGS += -I..
+KBUILD_CFLAGS += -I.. $(CRYPTODEV_CFLAGS)
+CFLAGS += -I.. $(CRYPTODEV_CFLAGS)
 
 comp_progs := cipher_comp hash_comp hmac_comp
 
diff --git a/drivers/staging/crypto/cryptodev/tests/async_cipher.c b/drivers/staging/crypto/cryptodev/tests/async_cipher.c
index 96ef7bc3b0a7..162a6958b709 100644
--- a/drivers/staging/crypto/cryptodev/tests/async_cipher.c
+++ b/drivers/staging/crypto/cryptodev/tests/async_cipher.c
@@ -15,6 +15,8 @@
 
 #include "testhelper.h"
 
+#ifdef ENABLE_ASYNC
+
 static int debug = 0;
 
 #define	DATA_SIZE	8*1024
@@ -327,4 +329,10 @@ main(int argc, char** argv)
 
 	return 0;
 }
-
+#else
+int
+main(int argc, char** argv)
+{
+	return (0);
+}
+#endif
diff --git a/drivers/staging/crypto/cryptodev/tests/async_hmac.c b/drivers/staging/crypto/cryptodev/tests/async_hmac.c
index 4083e897bdb1..97fd0c5731cb 100644
--- a/drivers/staging/crypto/cryptodev/tests/async_hmac.c
+++ b/drivers/staging/crypto/cryptodev/tests/async_hmac.c
@@ -16,6 +16,8 @@
 
 #include "testhelper.h"
 
+#ifdef ENABLE_ASYNC
+
 static int debug = 0;
 
 #define	DATA_SIZE	4096
@@ -292,3 +294,10 @@ main()
 
 	return 0;
 }
+#else
+int
+main(int argc, char** argv)
+{
+	return (0);
+}
+#endif
diff --git a/drivers/staging/crypto/cryptodev/tests/async_speed.c b/drivers/staging/crypto/cryptodev/tests/async_speed.c
index 4aea5e386533..1188599b7d7d 100644
--- a/drivers/staging/crypto/cryptodev/tests/async_speed.c
+++ b/drivers/staging/crypto/cryptodev/tests/async_speed.c
@@ -28,6 +28,8 @@
 #include <signal.h>
 #include <crypto/cryptodev.h>
 
+#ifdef ENABLE_ASYNC
+
 static double udifftimeval(struct timeval start, struct timeval end)
 {
 	return (double)(end.tv_usec - start.tv_usec) +
@@ -213,3 +215,11 @@ int main(void)
 	close(fd);
 	return 0;
 }
+
+#else
+int
+main(int argc, char** argv)
+{
+	return (0);
+}
+#endif
-- 
2.1.0

