mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frank Haverkamp <haver@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: arnd@arndb.de, gregkh@linuxfoundation.org,
	cody@linux.vnet.ibm.com, schwidefsky@de.ibm.com,
	utz.bacher@de.ibm.com, mmarek@suse.cz, rmallon@gmail.com,
	jsvogt@de.ibm.com, MIJUNG@de.ibm.com,
	cascardo@linux.vnet.ibm.com, michael@ibmra.de,
	haver@linux.vnet.ibm.com
Subject: [RFC 1/2] CRC32 Add GenWQE CRC to kernel CRC code
Date: Wed, 11 Dec 2013 17:49:22 +0100	[thread overview]
Message-ID: <1386780563-1722-1-git-send-email-haver@linux.vnet.ibm.com> (raw)
In-Reply-To: <1386592244-2521-7-git-send-email-haver@linux.vnet.ibm.com>

Our GenWQE driver is using a CRC32 polynom, which as far as I could
see, no one else is using in the kernel. In its original version we
implemented our own CRC32, but I think it is nicer to use the common
code as suggested by Greg.

I did not want to add yet another crc32g_table and waste (1KiB) memory
when no one else is using it. I tried to externalize the
crc32init_be_generic and crc32_be_generic functions. I failed. The
crc32init* I found is used to autogenerate code can is itself not part
of the resulting kernel.

As result I gave up on that approach and just added the GenWQE special
polynom in addition to the other 3 crc tables. I wanted to figure out
if it is possible in principle to use the generic code.

Is the consumption of 1KiB for a little table justifyable if it 
currently has just one user?

Signed-off-by: Frank Haverkamp <haver@linux.vnet.ibm.com>
---
 include/linux/crc32.h |    2 	2 +	0 -	0 !
 lib/crc32.c           |   10 	10 +	0 -	0 !
 lib/crc32defs.h       |    5 	5 +	0 -	0 !
 lib/gen_crc32table.c  |   39 	31 +	8 -	0 !
 4 files changed, 48 insertions(+), 8 deletions(-)

--- a/include/linux/crc32.h
+++ b/include/linux/crc32.h
@@ -11,6 +11,8 @@
 extern u32  crc32_le(u32 crc, unsigned char const *p, size_t len);
 extern u32  crc32_be(u32 crc, unsigned char const *p, size_t len);
 
+extern u32  __crc32g_be(u32 crc, unsigned char const *p, size_t len);
+
 /**
  * crc32_le_combine - Combine two crc32 check values into one. For two
  * 		      sequences of bytes, seq1 and seq2 with lengths len1
--- a/lib/crc32.c
+++ b/lib/crc32.c
@@ -339,14 +339,24 @@ u32 __pure crc32_be(u32 crc, unsigned ch
 {
 	return crc32_be_generic(crc, p, len, NULL, CRCPOLY_BE);
 }
+u32 __pure __crc32g_be(u32 crc, unsigned char const *p, size_t len)
+{
+	return crc32_be_generic(crc, p, len, NULL, CRC32G_POLY_BE);
+}
 #else
 u32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len)
 {
 	return crc32_be_generic(crc, p, len,
 			(const u32 (*)[256])crc32table_be, CRCPOLY_BE);
 }
+u32 __pure __crc32g_be(u32 crc, unsigned char const *p, size_t len)
+{
+	return crc32_be_generic(crc, p, len,
+			(const u32 (*)[256])crc32gtable_be, CRC32G_POLY_BE);
+}
 #endif
 EXPORT_SYMBOL(crc32_be);
+EXPORT_SYMBOL(__crc32g_be);
 
 #ifdef CONFIG_CRC32_SELFTEST
 
--- a/lib/crc32defs.h
+++ b/lib/crc32defs.h
@@ -13,6 +13,11 @@
  */
 #define CRC32C_POLY_LE 0x82F63B78
 
+/*
+ * This is the CRC32g polynomial, used by the GenWQE driver.
+ */
+#define CRC32G_POLY_BE 0x20044009
+
 /* Try to choose an implementation variant via Kconfig */
 #ifdef CONFIG_CRC32_SLICEBY8
 # define CRC_LE_BITS 64
--- a/lib/gen_crc32table.c
+++ b/lib/gen_crc32table.c
@@ -24,6 +24,7 @@
 static uint32_t crc32table_le[LE_TABLE_ROWS][256];
 static uint32_t crc32table_be[BE_TABLE_ROWS][256];
 static uint32_t crc32ctable_le[LE_TABLE_ROWS][256];
+static uint32_t crc32gtable_be[BE_TABLE_ROWS][256];
 
 /**
  * crc32init_le() - allocate and initialize LE table data
@@ -65,29 +66,40 @@ static void crc32cinit_le(void)
 }
 
 /**
- * crc32init_be() - allocate and initialize BE table data
+ * crc32init_be_generic() - allocate and initialize BE table data
  */
-static void crc32init_be(void)
+static void crc32init_be_generic(const uint32_t polynomial,
+				 uint32_t (*tab)[256])
 {
 	unsigned i, j;
 	uint32_t crc = 0x80000000;
 
-	crc32table_be[0][0] = 0;
+	tab[0][0] = 0;
 
 	for (i = 1; i < BE_TABLE_SIZE; i <<= 1) {
-		crc = (crc << 1) ^ ((crc & 0x80000000) ? CRCPOLY_BE : 0);
+		crc = (crc << 1) ^ ((crc & 0x80000000) ? polynomial : 0);
 		for (j = 0; j < i; j++)
-			crc32table_be[0][i + j] = crc ^ crc32table_be[0][j];
+			tab[0][i + j] = crc ^ tab[0][j];
 	}
 	for (i = 0; i < BE_TABLE_SIZE; i++) {
-		crc = crc32table_be[0][i];
+		crc = tab[0][i];
 		for (j = 1; j < BE_TABLE_ROWS; j++) {
-			crc = crc32table_be[0][(crc >> 24) & 0xff] ^ (crc << 8);
-			crc32table_be[j][i] = crc;
+			crc = tab[0][(crc >> 24) & 0xff] ^ (crc << 8);
+			tab[j][i] = crc;
 		}
 	}
 }
 
+static void crc32init_be(void)
+{
+	crc32init_be_generic(CRCPOLY_BE, crc32table_be);
+}
+
+static void crc32ginit_be(void)
+{
+	crc32init_be_generic(CRC32G_POLY_BE, crc32gtable_be);
+}
+
 static void output_table(uint32_t (*table)[256], int rows, int len, char *trans)
 {
 	int i, j;
@@ -126,6 +138,7 @@ int main(int argc, char** argv)
 			     BE_TABLE_SIZE, "tobe");
 		printf("};\n");
 	}
+
 	if (CRC_LE_BITS > 1) {
 		crc32cinit_le();
 		printf("static u32 __cacheline_aligned "
@@ -136,5 +149,15 @@ int main(int argc, char** argv)
 		printf("};\n");
 	}
 
+	if (CRC_BE_BITS > 1) {
+		crc32ginit_be();
+		printf("static u32 __cacheline_aligned "
+		       "crc32gtable_be[%d][%d] = {",
+		       BE_TABLE_ROWS, BE_TABLE_SIZE);
+		output_table(crc32gtable_be, LE_TABLE_ROWS,
+			     BE_TABLE_SIZE, "tobe");
+		printf("};\n");
+	}
+
 	return 0;
 }


  reply	other threads:[~2013-12-11 16:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-09 12:30 [PATCH 0/6] Generic WorkQueue Engine (GenWQE) device driver (v10) Frank Haverkamp
2013-12-09 12:30 ` [PATCH 1/6] GenWQE PCI support, health monitoring and recovery Frank Haverkamp
2013-12-09 12:30 ` [PATCH 2/6] GenWQE Character device and DDCB queue Frank Haverkamp
2013-12-09 12:30 ` [PATCH 3/6] GenWQE Utility functions Frank Haverkamp
2013-12-09 12:30 ` [PATCH 4/6] GenWQE Debugfs interfaces Frank Haverkamp
2013-12-09 12:30 ` [PATCH 5/6] GenWQE Sysfs interfaces Frank Haverkamp
2013-12-09 12:30 ` [PATCH 6/6] GenWQE Enable driver Frank Haverkamp
2013-12-11 16:49   ` Frank Haverkamp [this message]
2013-12-19  0:55     ` [RFC 1/2] CRC32 Add GenWQE CRC to kernel CRC code Greg KH
2013-12-19  9:10       ` Frank Haverkamp
2013-12-11 16:49   ` [RFC 2/2] GenWQE: Make use of the generic CRC kernel infrastructure Frank Haverkamp
2013-12-18 15:51 ` [PATCH 0/6] Generic WorkQueue Engine (GenWQE) device driver (v10) Frank Haverkamp
2013-12-19  0:52   ` Greg KH
2013-12-20  7:24     ` Frank Haverkamp

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=1386780563-1722-1-git-send-email-haver@linux.vnet.ibm.com \
    --to=haver@linux.vnet.ibm.com \
    --cc=MIJUNG@de.ibm.com \
    --cc=arnd@arndb.de \
    --cc=cascardo@linux.vnet.ibm.com \
    --cc=cody@linux.vnet.ibm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jsvogt@de.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael@ibmra.de \
    --cc=mmarek@suse.cz \
    --cc=rmallon@gmail.com \
    --cc=schwidefsky@de.ibm.com \
    --cc=utz.bacher@de.ibm.com \
    /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

all inboxes | Powered by JetHome®