From: "Nicholas A. Bellinger" Subject: [PATCH 2/2] crypto/crc32c: Add crc32c_cra_check_optimized for crc32c_intel Date: Thu, 10 Mar 2011 00:21:12 -0800 Message-ID: <1299745272-25477-3-git-send-email-nab@linux-iscsi.org> References: <1299745272-25477-1-git-send-email-nab@linux-iscsi.org> Cc: James Bottomley , Christoph Hellwig , Randy Dunlap , linux-scsi , Nicholas Bellinger , Herbert Xu To: linux-kernel , linux-crypto , Herbert Xu Return-path: In-Reply-To: <1299745272-25477-1-git-send-email-nab@linux-iscsi.org> Sender: linux-scsi-owner@vger.kernel.org List-Id: linux-crypto.vger.kernel.org From: Nicholas Bellinger 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 Cc: Herbert Xu --- 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