162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci/* Try to choose an implementation variant via Kconfig */
462306a36Sopenharmony_ci#ifdef CONFIG_CRC32_SLICEBY8
562306a36Sopenharmony_ci# define CRC_LE_BITS 64
662306a36Sopenharmony_ci# define CRC_BE_BITS 64
762306a36Sopenharmony_ci#endif
862306a36Sopenharmony_ci#ifdef CONFIG_CRC32_SLICEBY4
962306a36Sopenharmony_ci# define CRC_LE_BITS 32
1062306a36Sopenharmony_ci# define CRC_BE_BITS 32
1162306a36Sopenharmony_ci#endif
1262306a36Sopenharmony_ci#ifdef CONFIG_CRC32_SARWATE
1362306a36Sopenharmony_ci# define CRC_LE_BITS 8
1462306a36Sopenharmony_ci# define CRC_BE_BITS 8
1562306a36Sopenharmony_ci#endif
1662306a36Sopenharmony_ci#ifdef CONFIG_CRC32_BIT
1762306a36Sopenharmony_ci# define CRC_LE_BITS 1
1862306a36Sopenharmony_ci# define CRC_BE_BITS 1
1962306a36Sopenharmony_ci#endif
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci/*
2262306a36Sopenharmony_ci * How many bits at a time to use.  Valid values are 1, 2, 4, 8, 32 and 64.
2362306a36Sopenharmony_ci * For less performance-sensitive, use 4 or 8 to save table size.
2462306a36Sopenharmony_ci * For larger systems choose same as CPU architecture as default.
2562306a36Sopenharmony_ci * This works well on X86_64, SPARC64 systems. This may require some
2662306a36Sopenharmony_ci * elaboration after experiments with other architectures.
2762306a36Sopenharmony_ci */
2862306a36Sopenharmony_ci#ifndef CRC_LE_BITS
2962306a36Sopenharmony_ci#  ifdef CONFIG_64BIT
3062306a36Sopenharmony_ci#  define CRC_LE_BITS 64
3162306a36Sopenharmony_ci#  else
3262306a36Sopenharmony_ci#  define CRC_LE_BITS 32
3362306a36Sopenharmony_ci#  endif
3462306a36Sopenharmony_ci#endif
3562306a36Sopenharmony_ci#ifndef CRC_BE_BITS
3662306a36Sopenharmony_ci#  ifdef CONFIG_64BIT
3762306a36Sopenharmony_ci#  define CRC_BE_BITS 64
3862306a36Sopenharmony_ci#  else
3962306a36Sopenharmony_ci#  define CRC_BE_BITS 32
4062306a36Sopenharmony_ci#  endif
4162306a36Sopenharmony_ci#endif
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci/*
4462306a36Sopenharmony_ci * Little-endian CRC computation.  Used with serial bit streams sent
4562306a36Sopenharmony_ci * lsbit-first.  Be sure to use cpu_to_le32() to append the computed CRC.
4662306a36Sopenharmony_ci */
4762306a36Sopenharmony_ci#if CRC_LE_BITS > 64 || CRC_LE_BITS < 1 || CRC_LE_BITS == 16 || \
4862306a36Sopenharmony_ci	CRC_LE_BITS & CRC_LE_BITS-1
4962306a36Sopenharmony_ci# error "CRC_LE_BITS must be one of {1, 2, 4, 8, 32, 64}"
5062306a36Sopenharmony_ci#endif
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci/*
5362306a36Sopenharmony_ci * Big-endian CRC computation.  Used with serial bit streams sent
5462306a36Sopenharmony_ci * msbit-first.  Be sure to use cpu_to_be32() to append the computed CRC.
5562306a36Sopenharmony_ci */
5662306a36Sopenharmony_ci#if CRC_BE_BITS > 64 || CRC_BE_BITS < 1 || CRC_BE_BITS == 16 || \
5762306a36Sopenharmony_ci	CRC_BE_BITS & CRC_BE_BITS-1
5862306a36Sopenharmony_ci# error "CRC_BE_BITS must be one of {1, 2, 4, 8, 32, 64}"
5962306a36Sopenharmony_ci#endif
60