18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Aug 8, 2011 Bob Pearson with help from Joakim Tjernlund and George Spelvin
38c2ecf20Sopenharmony_ci * cleaned up code to current version of sparse and added the slicing-by-8
48c2ecf20Sopenharmony_ci * algorithm to the closely similar existing slicing-by-4 algorithm.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Oct 15, 2000 Matt Domsch <Matt_Domsch@dell.com>
78c2ecf20Sopenharmony_ci * Nicer crc32 functions/docs submitted by linux@horizon.com.  Thanks!
88c2ecf20Sopenharmony_ci * Code was from the public domain, copyright abandoned.  Code was
98c2ecf20Sopenharmony_ci * subsequently included in the kernel, thus was re-licensed under the
108c2ecf20Sopenharmony_ci * GNU GPL v2.
118c2ecf20Sopenharmony_ci *
128c2ecf20Sopenharmony_ci * Oct 12, 2000 Matt Domsch <Matt_Domsch@dell.com>
138c2ecf20Sopenharmony_ci * Same crc32 function was used in 5 other places in the kernel.
148c2ecf20Sopenharmony_ci * I made one version, and deleted the others.
158c2ecf20Sopenharmony_ci * There are various incantations of crc32().  Some use a seed of 0 or ~0.
168c2ecf20Sopenharmony_ci * Some xor at the end with ~0.  The generic crc32() function takes
178c2ecf20Sopenharmony_ci * seed as an argument, and doesn't xor at the end.  Then individual
188c2ecf20Sopenharmony_ci * users can do whatever they need.
198c2ecf20Sopenharmony_ci *   drivers/net/smc9194.c uses seed ~0, doesn't xor with ~0.
208c2ecf20Sopenharmony_ci *   fs/jffs2 uses seed 0, doesn't xor with ~0.
218c2ecf20Sopenharmony_ci *   fs/partitions/efi.c uses seed ~0, xor's with ~0.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * This source code is licensed under the GNU General Public License,
248c2ecf20Sopenharmony_ci * Version 2.  See the file COPYING for more details.
258c2ecf20Sopenharmony_ci */
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/* see: Documentation/staging/crc32.rst for a description of algorithms */
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#include <linux/crc32.h>
308c2ecf20Sopenharmony_ci#include <linux/crc32poly.h>
318c2ecf20Sopenharmony_ci#include <linux/module.h>
328c2ecf20Sopenharmony_ci#include <linux/types.h>
338c2ecf20Sopenharmony_ci#include <linux/sched.h>
348c2ecf20Sopenharmony_ci#include "crc32defs.h"
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#if CRC_LE_BITS > 8
378c2ecf20Sopenharmony_ci# define tole(x) ((__force u32) cpu_to_le32(x))
388c2ecf20Sopenharmony_ci#else
398c2ecf20Sopenharmony_ci# define tole(x) (x)
408c2ecf20Sopenharmony_ci#endif
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#if CRC_BE_BITS > 8
438c2ecf20Sopenharmony_ci# define tobe(x) ((__force u32) cpu_to_be32(x))
448c2ecf20Sopenharmony_ci#else
458c2ecf20Sopenharmony_ci# define tobe(x) (x)
468c2ecf20Sopenharmony_ci#endif
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#include "crc32table.h"
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ciMODULE_AUTHOR("Matt Domsch <Matt_Domsch@dell.com>");
518c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Various CRC32 calculations");
528c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#if CRC_LE_BITS > 8 || CRC_BE_BITS > 8
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/* implements slicing-by-4 or slicing-by-8 algorithm */
578c2ecf20Sopenharmony_cistatic inline u32 __pure
588c2ecf20Sopenharmony_cicrc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 (*tab)[256])
598c2ecf20Sopenharmony_ci{
608c2ecf20Sopenharmony_ci# ifdef __LITTLE_ENDIAN
618c2ecf20Sopenharmony_ci#  define DO_CRC(x) crc = t0[(crc ^ (x)) & 255] ^ (crc >> 8)
628c2ecf20Sopenharmony_ci#  define DO_CRC4 (t3[(q) & 255] ^ t2[(q >> 8) & 255] ^ \
638c2ecf20Sopenharmony_ci		   t1[(q >> 16) & 255] ^ t0[(q >> 24) & 255])
648c2ecf20Sopenharmony_ci#  define DO_CRC8 (t7[(q) & 255] ^ t6[(q >> 8) & 255] ^ \
658c2ecf20Sopenharmony_ci		   t5[(q >> 16) & 255] ^ t4[(q >> 24) & 255])
668c2ecf20Sopenharmony_ci# else
678c2ecf20Sopenharmony_ci#  define DO_CRC(x) crc = t0[((crc >> 24) ^ (x)) & 255] ^ (crc << 8)
688c2ecf20Sopenharmony_ci#  define DO_CRC4 (t0[(q) & 255] ^ t1[(q >> 8) & 255] ^ \
698c2ecf20Sopenharmony_ci		   t2[(q >> 16) & 255] ^ t3[(q >> 24) & 255])
708c2ecf20Sopenharmony_ci#  define DO_CRC8 (t4[(q) & 255] ^ t5[(q >> 8) & 255] ^ \
718c2ecf20Sopenharmony_ci		   t6[(q >> 16) & 255] ^ t7[(q >> 24) & 255])
728c2ecf20Sopenharmony_ci# endif
738c2ecf20Sopenharmony_ci	const u32 *b;
748c2ecf20Sopenharmony_ci	size_t    rem_len;
758c2ecf20Sopenharmony_ci# ifdef CONFIG_X86
768c2ecf20Sopenharmony_ci	size_t i;
778c2ecf20Sopenharmony_ci# endif
788c2ecf20Sopenharmony_ci	const u32 *t0=tab[0], *t1=tab[1], *t2=tab[2], *t3=tab[3];
798c2ecf20Sopenharmony_ci# if CRC_LE_BITS != 32
808c2ecf20Sopenharmony_ci	const u32 *t4 = tab[4], *t5 = tab[5], *t6 = tab[6], *t7 = tab[7];
818c2ecf20Sopenharmony_ci# endif
828c2ecf20Sopenharmony_ci	u32 q;
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	/* Align it */
858c2ecf20Sopenharmony_ci	if (unlikely((long)buf & 3 && len)) {
868c2ecf20Sopenharmony_ci		do {
878c2ecf20Sopenharmony_ci			DO_CRC(*buf++);
888c2ecf20Sopenharmony_ci		} while ((--len) && ((long)buf)&3);
898c2ecf20Sopenharmony_ci	}
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci# if CRC_LE_BITS == 32
928c2ecf20Sopenharmony_ci	rem_len = len & 3;
938c2ecf20Sopenharmony_ci	len = len >> 2;
948c2ecf20Sopenharmony_ci# else
958c2ecf20Sopenharmony_ci	rem_len = len & 7;
968c2ecf20Sopenharmony_ci	len = len >> 3;
978c2ecf20Sopenharmony_ci# endif
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	b = (const u32 *)buf;
1008c2ecf20Sopenharmony_ci# ifdef CONFIG_X86
1018c2ecf20Sopenharmony_ci	--b;
1028c2ecf20Sopenharmony_ci	for (i = 0; i < len; i++) {
1038c2ecf20Sopenharmony_ci# else
1048c2ecf20Sopenharmony_ci	for (--b; len; --len) {
1058c2ecf20Sopenharmony_ci# endif
1068c2ecf20Sopenharmony_ci		q = crc ^ *++b; /* use pre increment for speed */
1078c2ecf20Sopenharmony_ci# if CRC_LE_BITS == 32
1088c2ecf20Sopenharmony_ci		crc = DO_CRC4;
1098c2ecf20Sopenharmony_ci# else
1108c2ecf20Sopenharmony_ci		crc = DO_CRC8;
1118c2ecf20Sopenharmony_ci		q = *++b;
1128c2ecf20Sopenharmony_ci		crc ^= DO_CRC4;
1138c2ecf20Sopenharmony_ci# endif
1148c2ecf20Sopenharmony_ci	}
1158c2ecf20Sopenharmony_ci	len = rem_len;
1168c2ecf20Sopenharmony_ci	/* And the last few bytes */
1178c2ecf20Sopenharmony_ci	if (len) {
1188c2ecf20Sopenharmony_ci		u8 *p = (u8 *)(b + 1) - 1;
1198c2ecf20Sopenharmony_ci# ifdef CONFIG_X86
1208c2ecf20Sopenharmony_ci		for (i = 0; i < len; i++)
1218c2ecf20Sopenharmony_ci			DO_CRC(*++p); /* use pre increment for speed */
1228c2ecf20Sopenharmony_ci# else
1238c2ecf20Sopenharmony_ci		do {
1248c2ecf20Sopenharmony_ci			DO_CRC(*++p); /* use pre increment for speed */
1258c2ecf20Sopenharmony_ci		} while (--len);
1268c2ecf20Sopenharmony_ci# endif
1278c2ecf20Sopenharmony_ci	}
1288c2ecf20Sopenharmony_ci	return crc;
1298c2ecf20Sopenharmony_ci#undef DO_CRC
1308c2ecf20Sopenharmony_ci#undef DO_CRC4
1318c2ecf20Sopenharmony_ci#undef DO_CRC8
1328c2ecf20Sopenharmony_ci}
1338c2ecf20Sopenharmony_ci#endif
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci/**
1378c2ecf20Sopenharmony_ci * crc32_le_generic() - Calculate bitwise little-endian Ethernet AUTODIN II
1388c2ecf20Sopenharmony_ci *			CRC32/CRC32C
1398c2ecf20Sopenharmony_ci * @crc: seed value for computation.  ~0 for Ethernet, sometimes 0 for other
1408c2ecf20Sopenharmony_ci *	 uses, or the previous crc32/crc32c value if computing incrementally.
1418c2ecf20Sopenharmony_ci * @p: pointer to buffer over which CRC32/CRC32C is run
1428c2ecf20Sopenharmony_ci * @len: length of buffer @p
1438c2ecf20Sopenharmony_ci * @tab: little-endian Ethernet table
1448c2ecf20Sopenharmony_ci * @polynomial: CRC32/CRC32c LE polynomial
1458c2ecf20Sopenharmony_ci */
1468c2ecf20Sopenharmony_cistatic inline u32 __pure crc32_le_generic(u32 crc, unsigned char const *p,
1478c2ecf20Sopenharmony_ci					  size_t len, const u32 (*tab)[256],
1488c2ecf20Sopenharmony_ci					  u32 polynomial)
1498c2ecf20Sopenharmony_ci{
1508c2ecf20Sopenharmony_ci#if CRC_LE_BITS == 1
1518c2ecf20Sopenharmony_ci	int i;
1528c2ecf20Sopenharmony_ci	while (len--) {
1538c2ecf20Sopenharmony_ci		crc ^= *p++;
1548c2ecf20Sopenharmony_ci		for (i = 0; i < 8; i++)
1558c2ecf20Sopenharmony_ci			crc = (crc >> 1) ^ ((crc & 1) ? polynomial : 0);
1568c2ecf20Sopenharmony_ci	}
1578c2ecf20Sopenharmony_ci# elif CRC_LE_BITS == 2
1588c2ecf20Sopenharmony_ci	while (len--) {
1598c2ecf20Sopenharmony_ci		crc ^= *p++;
1608c2ecf20Sopenharmony_ci		crc = (crc >> 2) ^ tab[0][crc & 3];
1618c2ecf20Sopenharmony_ci		crc = (crc >> 2) ^ tab[0][crc & 3];
1628c2ecf20Sopenharmony_ci		crc = (crc >> 2) ^ tab[0][crc & 3];
1638c2ecf20Sopenharmony_ci		crc = (crc >> 2) ^ tab[0][crc & 3];
1648c2ecf20Sopenharmony_ci	}
1658c2ecf20Sopenharmony_ci# elif CRC_LE_BITS == 4
1668c2ecf20Sopenharmony_ci	while (len--) {
1678c2ecf20Sopenharmony_ci		crc ^= *p++;
1688c2ecf20Sopenharmony_ci		crc = (crc >> 4) ^ tab[0][crc & 15];
1698c2ecf20Sopenharmony_ci		crc = (crc >> 4) ^ tab[0][crc & 15];
1708c2ecf20Sopenharmony_ci	}
1718c2ecf20Sopenharmony_ci# elif CRC_LE_BITS == 8
1728c2ecf20Sopenharmony_ci	/* aka Sarwate algorithm */
1738c2ecf20Sopenharmony_ci	while (len--) {
1748c2ecf20Sopenharmony_ci		crc ^= *p++;
1758c2ecf20Sopenharmony_ci		crc = (crc >> 8) ^ tab[0][crc & 255];
1768c2ecf20Sopenharmony_ci	}
1778c2ecf20Sopenharmony_ci# else
1788c2ecf20Sopenharmony_ci	crc = (__force u32) __cpu_to_le32(crc);
1798c2ecf20Sopenharmony_ci	crc = crc32_body(crc, p, len, tab);
1808c2ecf20Sopenharmony_ci	crc = __le32_to_cpu((__force __le32)crc);
1818c2ecf20Sopenharmony_ci#endif
1828c2ecf20Sopenharmony_ci	return crc;
1838c2ecf20Sopenharmony_ci}
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci#if CRC_LE_BITS == 1
1868c2ecf20Sopenharmony_ciu32 __pure __weak crc32_le(u32 crc, unsigned char const *p, size_t len)
1878c2ecf20Sopenharmony_ci{
1888c2ecf20Sopenharmony_ci	return crc32_le_generic(crc, p, len, NULL, CRC32_POLY_LE);
1898c2ecf20Sopenharmony_ci}
1908c2ecf20Sopenharmony_ciu32 __pure __weak __crc32c_le(u32 crc, unsigned char const *p, size_t len)
1918c2ecf20Sopenharmony_ci{
1928c2ecf20Sopenharmony_ci	return crc32_le_generic(crc, p, len, NULL, CRC32C_POLY_LE);
1938c2ecf20Sopenharmony_ci}
1948c2ecf20Sopenharmony_ci#else
1958c2ecf20Sopenharmony_ciu32 __pure __weak crc32_le(u32 crc, unsigned char const *p, size_t len)
1968c2ecf20Sopenharmony_ci{
1978c2ecf20Sopenharmony_ci	return crc32_le_generic(crc, p, len,
1988c2ecf20Sopenharmony_ci			(const u32 (*)[256])crc32table_le, CRC32_POLY_LE);
1998c2ecf20Sopenharmony_ci}
2008c2ecf20Sopenharmony_ciu32 __pure __weak __crc32c_le(u32 crc, unsigned char const *p, size_t len)
2018c2ecf20Sopenharmony_ci{
2028c2ecf20Sopenharmony_ci	return crc32_le_generic(crc, p, len,
2038c2ecf20Sopenharmony_ci			(const u32 (*)[256])crc32ctable_le, CRC32C_POLY_LE);
2048c2ecf20Sopenharmony_ci}
2058c2ecf20Sopenharmony_ci#endif
2068c2ecf20Sopenharmony_ciEXPORT_SYMBOL(crc32_le);
2078c2ecf20Sopenharmony_ciEXPORT_SYMBOL(__crc32c_le);
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ciu32 __pure crc32_le_base(u32, unsigned char const *, size_t) __alias(crc32_le);
2108c2ecf20Sopenharmony_ciu32 __pure __crc32c_le_base(u32, unsigned char const *, size_t) __alias(__crc32c_le);
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci/*
2138c2ecf20Sopenharmony_ci * This multiplies the polynomials x and y modulo the given modulus.
2148c2ecf20Sopenharmony_ci * This follows the "little-endian" CRC convention that the lsbit
2158c2ecf20Sopenharmony_ci * represents the highest power of x, and the msbit represents x^0.
2168c2ecf20Sopenharmony_ci */
2178c2ecf20Sopenharmony_cistatic u32 __attribute_const__ gf2_multiply(u32 x, u32 y, u32 modulus)
2188c2ecf20Sopenharmony_ci{
2198c2ecf20Sopenharmony_ci	u32 product = x & 1 ? y : 0;
2208c2ecf20Sopenharmony_ci	int i;
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci	for (i = 0; i < 31; i++) {
2238c2ecf20Sopenharmony_ci		product = (product >> 1) ^ (product & 1 ? modulus : 0);
2248c2ecf20Sopenharmony_ci		x >>= 1;
2258c2ecf20Sopenharmony_ci		product ^= x & 1 ? y : 0;
2268c2ecf20Sopenharmony_ci	}
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci	return product;
2298c2ecf20Sopenharmony_ci}
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci/**
2328c2ecf20Sopenharmony_ci * crc32_generic_shift - Append @len 0 bytes to crc, in logarithmic time
2338c2ecf20Sopenharmony_ci * @crc: The original little-endian CRC (i.e. lsbit is x^31 coefficient)
2348c2ecf20Sopenharmony_ci * @len: The number of bytes. @crc is multiplied by x^(8*@len)
2358c2ecf20Sopenharmony_ci * @polynomial: The modulus used to reduce the result to 32 bits.
2368c2ecf20Sopenharmony_ci *
2378c2ecf20Sopenharmony_ci * It's possible to parallelize CRC computations by computing a CRC
2388c2ecf20Sopenharmony_ci * over separate ranges of a buffer, then summing them.
2398c2ecf20Sopenharmony_ci * This shifts the given CRC by 8*len bits (i.e. produces the same effect
2408c2ecf20Sopenharmony_ci * as appending len bytes of zero to the data), in time proportional
2418c2ecf20Sopenharmony_ci * to log(len).
2428c2ecf20Sopenharmony_ci */
2438c2ecf20Sopenharmony_cistatic u32 __attribute_const__ crc32_generic_shift(u32 crc, size_t len,
2448c2ecf20Sopenharmony_ci						   u32 polynomial)
2458c2ecf20Sopenharmony_ci{
2468c2ecf20Sopenharmony_ci	u32 power = polynomial;	/* CRC of x^32 */
2478c2ecf20Sopenharmony_ci	int i;
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci	/* Shift up to 32 bits in the simple linear way */
2508c2ecf20Sopenharmony_ci	for (i = 0; i < 8 * (int)(len & 3); i++)
2518c2ecf20Sopenharmony_ci		crc = (crc >> 1) ^ (crc & 1 ? polynomial : 0);
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci	len >>= 2;
2548c2ecf20Sopenharmony_ci	if (!len)
2558c2ecf20Sopenharmony_ci		return crc;
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	for (;;) {
2588c2ecf20Sopenharmony_ci		/* "power" is x^(2^i), modulo the polynomial */
2598c2ecf20Sopenharmony_ci		if (len & 1)
2608c2ecf20Sopenharmony_ci			crc = gf2_multiply(crc, power, polynomial);
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci		len >>= 1;
2638c2ecf20Sopenharmony_ci		if (!len)
2648c2ecf20Sopenharmony_ci			break;
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci		/* Square power, advancing to x^(2^(i+1)) */
2678c2ecf20Sopenharmony_ci		power = gf2_multiply(power, power, polynomial);
2688c2ecf20Sopenharmony_ci	}
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	return crc;
2718c2ecf20Sopenharmony_ci}
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ciu32 __attribute_const__ crc32_le_shift(u32 crc, size_t len)
2748c2ecf20Sopenharmony_ci{
2758c2ecf20Sopenharmony_ci	return crc32_generic_shift(crc, len, CRC32_POLY_LE);
2768c2ecf20Sopenharmony_ci}
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ciu32 __attribute_const__ __crc32c_le_shift(u32 crc, size_t len)
2798c2ecf20Sopenharmony_ci{
2808c2ecf20Sopenharmony_ci	return crc32_generic_shift(crc, len, CRC32C_POLY_LE);
2818c2ecf20Sopenharmony_ci}
2828c2ecf20Sopenharmony_ciEXPORT_SYMBOL(crc32_le_shift);
2838c2ecf20Sopenharmony_ciEXPORT_SYMBOL(__crc32c_le_shift);
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci/**
2868c2ecf20Sopenharmony_ci * crc32_be_generic() - Calculate bitwise big-endian Ethernet AUTODIN II CRC32
2878c2ecf20Sopenharmony_ci * @crc: seed value for computation.  ~0 for Ethernet, sometimes 0 for
2888c2ecf20Sopenharmony_ci *	other uses, or the previous crc32 value if computing incrementally.
2898c2ecf20Sopenharmony_ci * @p: pointer to buffer over which CRC32 is run
2908c2ecf20Sopenharmony_ci * @len: length of buffer @p
2918c2ecf20Sopenharmony_ci * @tab: big-endian Ethernet table
2928c2ecf20Sopenharmony_ci * @polynomial: CRC32 BE polynomial
2938c2ecf20Sopenharmony_ci */
2948c2ecf20Sopenharmony_cistatic inline u32 __pure crc32_be_generic(u32 crc, unsigned char const *p,
2958c2ecf20Sopenharmony_ci					  size_t len, const u32 (*tab)[256],
2968c2ecf20Sopenharmony_ci					  u32 polynomial)
2978c2ecf20Sopenharmony_ci{
2988c2ecf20Sopenharmony_ci#if CRC_BE_BITS == 1
2998c2ecf20Sopenharmony_ci	int i;
3008c2ecf20Sopenharmony_ci	while (len--) {
3018c2ecf20Sopenharmony_ci		crc ^= *p++ << 24;
3028c2ecf20Sopenharmony_ci		for (i = 0; i < 8; i++)
3038c2ecf20Sopenharmony_ci			crc =
3048c2ecf20Sopenharmony_ci			    (crc << 1) ^ ((crc & 0x80000000) ? polynomial :
3058c2ecf20Sopenharmony_ci					  0);
3068c2ecf20Sopenharmony_ci	}
3078c2ecf20Sopenharmony_ci# elif CRC_BE_BITS == 2
3088c2ecf20Sopenharmony_ci	while (len--) {
3098c2ecf20Sopenharmony_ci		crc ^= *p++ << 24;
3108c2ecf20Sopenharmony_ci		crc = (crc << 2) ^ tab[0][crc >> 30];
3118c2ecf20Sopenharmony_ci		crc = (crc << 2) ^ tab[0][crc >> 30];
3128c2ecf20Sopenharmony_ci		crc = (crc << 2) ^ tab[0][crc >> 30];
3138c2ecf20Sopenharmony_ci		crc = (crc << 2) ^ tab[0][crc >> 30];
3148c2ecf20Sopenharmony_ci	}
3158c2ecf20Sopenharmony_ci# elif CRC_BE_BITS == 4
3168c2ecf20Sopenharmony_ci	while (len--) {
3178c2ecf20Sopenharmony_ci		crc ^= *p++ << 24;
3188c2ecf20Sopenharmony_ci		crc = (crc << 4) ^ tab[0][crc >> 28];
3198c2ecf20Sopenharmony_ci		crc = (crc << 4) ^ tab[0][crc >> 28];
3208c2ecf20Sopenharmony_ci	}
3218c2ecf20Sopenharmony_ci# elif CRC_BE_BITS == 8
3228c2ecf20Sopenharmony_ci	while (len--) {
3238c2ecf20Sopenharmony_ci		crc ^= *p++ << 24;
3248c2ecf20Sopenharmony_ci		crc = (crc << 8) ^ tab[0][crc >> 24];
3258c2ecf20Sopenharmony_ci	}
3268c2ecf20Sopenharmony_ci# else
3278c2ecf20Sopenharmony_ci	crc = (__force u32) __cpu_to_be32(crc);
3288c2ecf20Sopenharmony_ci	crc = crc32_body(crc, p, len, tab);
3298c2ecf20Sopenharmony_ci	crc = __be32_to_cpu((__force __be32)crc);
3308c2ecf20Sopenharmony_ci# endif
3318c2ecf20Sopenharmony_ci	return crc;
3328c2ecf20Sopenharmony_ci}
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci#if CRC_BE_BITS == 1
3358c2ecf20Sopenharmony_ciu32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len)
3368c2ecf20Sopenharmony_ci{
3378c2ecf20Sopenharmony_ci	return crc32_be_generic(crc, p, len, NULL, CRC32_POLY_BE);
3388c2ecf20Sopenharmony_ci}
3398c2ecf20Sopenharmony_ci#else
3408c2ecf20Sopenharmony_ciu32 __pure crc32_be(u32 crc, unsigned char const *p, size_t len)
3418c2ecf20Sopenharmony_ci{
3428c2ecf20Sopenharmony_ci	return crc32_be_generic(crc, p, len,
3438c2ecf20Sopenharmony_ci			(const u32 (*)[256])crc32table_be, CRC32_POLY_BE);
3448c2ecf20Sopenharmony_ci}
3458c2ecf20Sopenharmony_ci#endif
3468c2ecf20Sopenharmony_ciEXPORT_SYMBOL(crc32_be);
347