lkml.org 
[lkml]   [2011]   [Mar]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/2] crypto/crc32c: Add crc32c_cra_check_optimized for crc32c_intel
Date
From: Nicholas Bellinger <nab@linux-iscsi.org>

This patch adds crc32c_cra_check_optimized() for use by the new
struct crypto_alg->cra_check_optimized() API caller in order to
call request_module() to load crc32c_intel.ko for CRC32C instruction
offload when available on CONFIG_X86 w/ SSE v4.2 compatiable hardware.

Signed-off-by: Nicholas A. Bellinger <nab@linux-iscsi.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
---
crypto/crc32c.c | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/crypto/crc32c.c b/crypto/crc32c.c
index de9e55c..3f1d3a3 100644
--- a/crypto/crc32c.c
+++ b/crypto/crc32c.c
@@ -44,6 +44,8 @@
#define CHKSUM_BLOCK_SIZE 1
#define CHKSUM_DIGEST_SIZE 4

+static int crc32c_offload_enabled;
+
struct chksum_ctx {
u32 key;
};
@@ -221,6 +223,24 @@ static int crc32c_cra_init(struct crypto_tfm *tfm)
return 0;
}

+static void crc32c_cra_check_optimized(struct crypto_alg *alg)
+{
+ if (crc32c_offload_enabled)
+ return;
+#ifdef CONFIG_X86
+ /*
+ * For cpu_has_xmm4_2 go ahead and load crc32c_intel.ko in order so
+ * crypto_alloc_hash("crc32c", ...) will automatically use SSE v4.2
+ * CRC32C instruction offload.
+ */
+ if (cpu_has_xmm4_2) {
+ int rc = request_module("crc32c_intel");
+ if (rc == 0)
+ crc32c_offload_enabled = 1;
+ }
+#endif
+}
+
static struct shash_alg alg = {
.digestsize = CHKSUM_DIGEST_SIZE,
.setkey = chksum_setkey,
@@ -239,11 +259,14 @@ static struct shash_alg alg = {
.cra_ctxsize = sizeof(struct chksum_ctx),
.cra_module = THIS_MODULE,
.cra_init = crc32c_cra_init,
+ .cra_check_optimized = crc32c_cra_check_optimized,
}
};

static int __init crc32c_mod_init(void)
{
+ crc32c_offload_enabled = 0;
+
return crypto_register_shash(&alg);
}

--
1.5.6.5


\
 
 \ /
  Last update: 2011-03-10 09:23    [W:0.102 / U:0.896 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site