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