Skip to contentSkip to conversation

lib: Add support for DIF CRC

PATCH In review Martin K. Petersen 2 participants 2 messages Jan 30, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: Add support for DIF CRC

Add support for the T10 Data Integrity Field CRC.

include/linux/crc-t10dif.h new file +9 -0
diff -r f5ec697e8b10 include/linux/crc-t10dif.h
@@ -0,0 +1,9 @@
+#ifndef _LINUX_CRC_T10DIF_H
+#define _LINUX_CRC_T10DIF_H
+
+#include <linux/types.h>
+
+const __u16 t10_dif_crc_table[256];
+__u16 crc_t10dif(unsigned char const *, size_t);
+
+#endif
lib/Kconfig +7 -0
diff -r f5ec697e8b10 lib/Kconfig
@@ -22,6 +22,13 @@ config CRC16
 	  modules require CRC16 functions, but a module built outside
 	  the kernel tree does. Such modules that use library CRC16
 	  functions require M here.
+
+config CRC_T10DIF
+	tristate "CRC calculation for the T10 Data Integrity Field"
+	help
+	  This option is only needed if a module that's not in the
+	  kernel tree needs to calculate CRC checks for use with the
+	  SCSI data integrity subsystem.
 
 config CRC_ITU_T
 	tristate "CRC ITU-T V.41 functions"
lib/Makefile +1 -0
diff -r f5ec697e8b10 lib/Makefile
@@ -44,6 +44,7 @@ obj-$(CONFIG_BITREVERSE) += bitrev.o
 obj-$(CONFIG_BITREVERSE) += bitrev.o
 obj-$(CONFIG_CRC_CCITT)	+= crc-ccitt.o
 obj-$(CONFIG_CRC16)	+= crc16.o
+obj-$(CONFIG_CRC_T10DIF)+= crc-t10dif.o
 obj-$(CONFIG_CRC_ITU_T)	+= crc-itu-t.o
 obj-$(CONFIG_CRC32)	+= crc32.o
 obj-$(CONFIG_CRC7)	+= crc7.o
lib/crc-t10dif.c new file +68 -0

68 lines not on this page · raw message

#1 lore raw
Quoted 13 lines · Martin K. Petersen

diff -r f5ec697e8b10 include/linux/crc-t10dif.h

include/linux/crc-t10dif.h new file +9 -0
@@ -0,0 +1,9 @@
+#ifndef _LINUX_CRC_T10DIF_H
+#define _LINUX_CRC_T10DIF_H
+
+#include <linux/types.h>
+
+const __u16 t10_dif_crc_table[256];
+__u16 crc_t10dif(unsigned char const *, size_t);
+
+const __u16 t10_dif_crc_table[256] = {

...

Quoted 4 lines
include/linux/crc-t10dif.h new file +4 -0
+};
+
+__u16 crc_t10dif(const unsigned char *buffer, size_t len)
+{

...

include/linux/crc-t10dif.h

Quoted 3 lines
include/linux/crc-t10dif.h new file +3 -0
+}
+
+EXPORT_SYMBOL(crc_t10dif);

One minor nitpick still: if t10_dif_crc_table is not EXPORT_SYMBOLed, it should be static, since I do not see a reason to only make it available to built-in code.

So either make the table static too, or EXPORT it. I am not sure if any code needs to access the table directly, though, so I'd be going for the static.