-#if defined(__linux__)
-#include <linux/obd_cksum.h>
-#elif defined(__APPLE__)
-#include <darwin/obd_chksum.h>
-#elif defined(__WINNT__)
-#include <winnt/obd_cksum.h>
-#else
-#error Unsupported operating system.
-#endif
-
-#include <lustre/lustre_idl.h>
-
-/*
- * Checksums
- */
-
-#ifndef HAVE_ARCH_CRC32
-/* crc32_le lifted from the Linux kernel, which had the following to say:
- *
- * This code is in the public domain; copyright abandoned.
- * Liability for non-performance of this code is limited to the amount
- * you paid for it. Since it is distributed for free, your refund will
- * be very very small. If it breaks, you get to keep both pieces.
- */
-#define CRCPOLY_LE 0xedb88320
-/**
- * crc32_le() - Calculate bitwise little-endian Ethernet AUTODIN II CRC32
- * \param crc seed value for computation. ~0 for Ethernet, sometimes 0 for
- * other uses, or the previous crc32 value if computing incrementally.
- * \param p - pointer to buffer over which CRC is run
- * \param len- length of buffer \a p
- */
-static inline __u32 crc32_le(__u32 crc, unsigned char const *p, size_t len)
-{
- int i;
- while (len--) {
- crc ^= *p++;
- for (i = 0; i < 8; i++)
- crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
- }
- return crc;
-}
-#endif
-
-#ifdef HAVE_ADLER
-/* Adler-32 is supported */
-#define CHECKSUM_ADLER OBD_CKSUM_ADLER
-#else
-#define CHECKSUM_ADLER 0
-#endif
-
-#ifdef X86_FEATURE_XMM4_2
-/* Call Nehalem+ CRC32C harware acceleration instruction on individual bytes. */
-static inline __u32 crc32c_hw_byte(__u32 crc, unsigned char const *p,
- size_t bytes)
-{
- while (bytes--) {
- __asm__ __volatile__ (
- ".byte 0xf2, 0xf, 0x38, 0xf0, 0xf1"
- : "=S"(crc)
- : "0"(crc), "c"(*p)
- );
- p++;
- }
-
- return crc;
-}
-
-#if BITS_PER_LONG > 32
-#define WORD_SHIFT 3
-#define WORD_MASK 7
-#define REX "0x48, "
-#else
-#define WORD_SHIFT 2
-#define WORD_MASK 3
-#define REX ""
-#endif
-
-/* Do we need to worry about unaligned input data here? */
-static inline __u32 crc32c_hw(__u32 crc, unsigned char const *p, size_t len)
-{
- unsigned int words = len >> WORD_SHIFT;
- unsigned int bytes = len & WORD_MASK;
- long *ptmp = (long *)p;
-
- while (words--) {
- __asm__ __volatile__(
- ".byte 0xf2, " REX "0xf, 0x38, 0xf1, 0xf1;"
- : "=S"(crc)
- : "0"(crc), "c"(*ptmp)
- );
- ptmp++;
- }
-
- if (bytes)
- crc = crc32c_hw_byte(crc, (unsigned char *)ptmp, bytes);