crc32defs.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Try to choose an implementation variant via Kconfig */
  3. #ifdef CONFIG_CRC32_SLICEBY8
  4. # define CRC_LE_BITS 64
  5. # define CRC_BE_BITS 64
  6. #endif
  7. #ifdef CONFIG_CRC32_SLICEBY4
  8. # define CRC_LE_BITS 32
  9. # define CRC_BE_BITS 32
  10. #endif
  11. #ifdef CONFIG_CRC32_SARWATE
  12. # define CRC_LE_BITS 8
  13. # define CRC_BE_BITS 8
  14. #endif
  15. #ifdef CONFIG_CRC32_BIT
  16. # define CRC_LE_BITS 1
  17. # define CRC_BE_BITS 1
  18. #endif
  19. /*
  20. * How many bits at a time to use. Valid values are 1, 2, 4, 8, 32 and 64.
  21. * For less performance-sensitive, use 4 or 8 to save table size.
  22. * For larger systems choose same as CPU architecture as default.
  23. * This works well on X86_64, SPARC64 systems. This may require some
  24. * elaboration after experiments with other architectures.
  25. */
  26. #ifndef CRC_LE_BITS
  27. # ifdef CONFIG_64BIT
  28. # define CRC_LE_BITS 64
  29. # else
  30. # define CRC_LE_BITS 32
  31. # endif
  32. #endif
  33. #ifndef CRC_BE_BITS
  34. # ifdef CONFIG_64BIT
  35. # define CRC_BE_BITS 64
  36. # else
  37. # define CRC_BE_BITS 32
  38. # endif
  39. #endif
  40. /*
  41. * Little-endian CRC computation. Used with serial bit streams sent
  42. * lsbit-first. Be sure to use cpu_to_le32() to append the computed CRC.
  43. */
  44. #if CRC_LE_BITS > 64 || CRC_LE_BITS < 1 || CRC_LE_BITS == 16 || \
  45. CRC_LE_BITS & CRC_LE_BITS-1
  46. # error "CRC_LE_BITS must be one of {1, 2, 4, 8, 32, 64}"
  47. #endif
  48. /*
  49. * Big-endian CRC computation. Used with serial bit streams sent
  50. * msbit-first. Be sure to use cpu_to_be32() to append the computed CRC.
  51. */
  52. #if CRC_BE_BITS > 64 || CRC_BE_BITS < 1 || CRC_BE_BITS == 16 || \
  53. CRC_BE_BITS & CRC_BE_BITS-1
  54. # error "CRC_BE_BITS must be one of {1, 2, 4, 8, 32, 64}"
  55. #endif