From: "Nicholas A. Bellinger" <nab@linux-iscsi.org>
To: linux-kernel <linux-kernel@vger.kernel.org>,
linux-crypto <linux-crypto@vger.kernel.org>,
Herbert Xu <herbert@gondor.apana.org.au>
Cc: James Bottomley <James.Bottomley@suse.de>,
Christoph Hellwig <hch@lst.de>,
Randy Dunlap <rdunlap@xenotime.net>,
linux-scsi <linux-scsi@vger.kernel.org>,
Nicholas Bellinger <nab@linux-iscsi.org>,
Herbert Xu <herbert@gondor.apana.org.au>
Subject: [PATCH 2/2] crypto/crc32c: Add crc32c_cra_check_optimized for crc32c_intel
Date: Thu, 10 Mar 2011 00:21:12 -0800 [thread overview]
Message-ID: <1299745272-25477-3-git-send-email-nab@linux-iscsi.org> (raw)
In-Reply-To: <1299745272-25477-1-git-send-email-nab@linux-iscsi.org>
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
next prev parent reply other threads:[~2011-03-10 8:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-10 8:21 [PATCH 0/2] Add struct crypto_alg->cra_check_optimized for crc32c_intel Nicholas A. Bellinger
2011-03-10 8:21 ` [PATCH 1/2] crypto: Add struct crypto_alg->cra_check_optimized Nicholas A. Bellinger
2011-03-10 8:21 ` Nicholas A. Bellinger [this message]
2011-03-10 8:43 ` [PATCH 0/2] Add struct crypto_alg->cra_check_optimized for crc32c_intel Herbert Xu
2011-03-10 8:54 ` Nicholas A. Bellinger
2011-03-10 9:09 ` Herbert Xu
2011-03-10 9:13 ` Nicholas A. Bellinger
2011-03-10 10:05 ` Nicholas A. Bellinger
2011-03-13 9:01 ` Herbert Xu
2011-03-14 12:14 ` Nicholas A. Bellinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1299745272-25477-3-git-send-email-nab@linux-iscsi.org \
--to=nab@linux-iscsi.org \
--cc=James.Bottomley@suse.de \
--cc=hch@lst.de \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=rdunlap@xenotime.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).