1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 246c5801eSDarrick J. Wong 35cde7656SDarrick J. Wong /* Try to choose an implementation variant via Kconfig */ 45cde7656SDarrick J. Wong #ifdef CONFIG_CRC32_SLICEBY8 55cde7656SDarrick J. Wong # define CRC_LE_BITS 64 65cde7656SDarrick J. Wong # define CRC_BE_BITS 64 75cde7656SDarrick J. Wong #endif 85cde7656SDarrick J. Wong #ifdef CONFIG_CRC32_SLICEBY4 95cde7656SDarrick J. Wong # define CRC_LE_BITS 32 105cde7656SDarrick J. Wong # define CRC_BE_BITS 32 115cde7656SDarrick J. Wong #endif 125cde7656SDarrick J. Wong #ifdef CONFIG_CRC32_SARWATE 135cde7656SDarrick J. Wong # define CRC_LE_BITS 8 145cde7656SDarrick J. Wong # define CRC_BE_BITS 8 155cde7656SDarrick J. Wong #endif 165cde7656SDarrick J. Wong #ifdef CONFIG_CRC32_BIT 175cde7656SDarrick J. Wong # define CRC_LE_BITS 1 185cde7656SDarrick J. Wong # define CRC_BE_BITS 1 195cde7656SDarrick J. Wong #endif 205cde7656SDarrick J. Wong 2146c5801eSDarrick J. Wong /* 22324eb0f1SBob Pearson * How many bits at a time to use. Valid values are 1, 2, 4, 8, 32 and 64. 23324eb0f1SBob Pearson * For less performance-sensitive, use 4 or 8 to save table size. 24324eb0f1SBob Pearson * For larger systems choose same as CPU architecture as default. 25324eb0f1SBob Pearson * This works well on X86_64, SPARC64 systems. This may require some 26324eb0f1SBob Pearson * elaboration after experiments with other architectures. 27324eb0f1SBob Pearson */ 281da177e4SLinus Torvalds #ifndef CRC_LE_BITS 29324eb0f1SBob Pearson # ifdef CONFIG_64BIT 30324eb0f1SBob Pearson # define CRC_LE_BITS 64 31324eb0f1SBob Pearson # else 329a1dbf6aSBob Pearson # define CRC_LE_BITS 32 331da177e4SLinus Torvalds # endif 34324eb0f1SBob Pearson #endif 351da177e4SLinus Torvalds #ifndef CRC_BE_BITS 36324eb0f1SBob Pearson # ifdef CONFIG_64BIT 37324eb0f1SBob Pearson # define CRC_BE_BITS 64 38324eb0f1SBob Pearson # else 399a1dbf6aSBob Pearson # define CRC_BE_BITS 32 401da177e4SLinus Torvalds # endif 41324eb0f1SBob Pearson #endif 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds /* 441da177e4SLinus Torvalds * Little-endian CRC computation. Used with serial bit streams sent 451da177e4SLinus Torvalds * lsbit-first. Be sure to use cpu_to_le32() to append the computed CRC. 461da177e4SLinus Torvalds */ 47324eb0f1SBob Pearson #if CRC_LE_BITS > 64 || CRC_LE_BITS < 1 || CRC_LE_BITS == 16 || \ 489a1dbf6aSBob Pearson CRC_LE_BITS & CRC_LE_BITS-1 49324eb0f1SBob Pearson # error "CRC_LE_BITS must be one of {1, 2, 4, 8, 32, 64}" 501da177e4SLinus Torvalds #endif 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds /* 531da177e4SLinus Torvalds * Big-endian CRC computation. Used with serial bit streams sent 541da177e4SLinus Torvalds * msbit-first. Be sure to use cpu_to_be32() to append the computed CRC. 551da177e4SLinus Torvalds */ 56324eb0f1SBob Pearson #if CRC_BE_BITS > 64 || CRC_BE_BITS < 1 || CRC_BE_BITS == 16 || \ 579a1dbf6aSBob Pearson CRC_BE_BITS & CRC_BE_BITS-1 58324eb0f1SBob Pearson # error "CRC_BE_BITS must be one of {1, 2, 4, 8, 32, 64}" 591da177e4SLinus Torvalds #endif 60