1feba04fdSColy Li /* SPDX-License-Identifier: GPL-2.0 */
2feba04fdSColy Li /*
3feba04fdSColy Li * See lib/crc64.c for the related specification and polynomial arithmetic.
4feba04fdSColy Li */
5feba04fdSColy Li #ifndef _LINUX_CRC64_H
6feba04fdSColy Li #define _LINUX_CRC64_H
7feba04fdSColy Li
8feba04fdSColy Li #include <linux/types.h>
9feba04fdSColy Li
10*067bc871SEric Biggers u64 crc64_be_arch(u64 crc, const u8 *p, size_t len);
11*067bc871SEric Biggers u64 crc64_be_generic(u64 crc, const u8 *p, size_t len);
12*067bc871SEric Biggers u64 crc64_nvme_arch(u64 crc, const u8 *p, size_t len);
13*067bc871SEric Biggers u64 crc64_nvme_generic(u64 crc, const u8 *p, size_t len);
14*067bc871SEric Biggers
15*067bc871SEric Biggers /**
16*067bc871SEric Biggers * crc64_be - Calculate bitwise big-endian ECMA-182 CRC64
17*067bc871SEric Biggers * @crc: seed value for computation. 0 or (u64)~0 for a new CRC calculation,
18*067bc871SEric Biggers * or the previous crc64 value if computing incrementally.
19*067bc871SEric Biggers * @p: pointer to buffer over which CRC64 is run
20*067bc871SEric Biggers * @len: length of buffer @p
21*067bc871SEric Biggers */
crc64_be(u64 crc,const void * p,size_t len)22*067bc871SEric Biggers static inline u64 crc64_be(u64 crc, const void *p, size_t len)
23*067bc871SEric Biggers {
24*067bc871SEric Biggers if (IS_ENABLED(CONFIG_CRC64_ARCH))
25*067bc871SEric Biggers return crc64_be_arch(crc, p, len);
26*067bc871SEric Biggers return crc64_be_generic(crc, p, len);
27*067bc871SEric Biggers }
28cbc0a40eSKeith Busch
29feb541bfSEric Biggers /**
30f6c3f6fbSEric Biggers * crc64_nvme - Calculate CRC64-NVME
31feb541bfSEric Biggers * @crc: seed value for computation. 0 for a new CRC calculation, or the
32feb541bfSEric Biggers * previous crc64 value if computing incrementally.
33feb541bfSEric Biggers * @p: pointer to buffer over which CRC64 is run
34feb541bfSEric Biggers * @len: length of buffer @p
35f6c3f6fbSEric Biggers *
36f6c3f6fbSEric Biggers * This computes the CRC64 defined in the NVME NVM Command Set Specification,
37f6c3f6fbSEric Biggers * *including the bitwise inversion at the beginning and end*.
38feb541bfSEric Biggers */
crc64_nvme(u64 crc,const void * p,size_t len)39*067bc871SEric Biggers static inline u64 crc64_nvme(u64 crc, const void *p, size_t len)
40feb541bfSEric Biggers {
41*067bc871SEric Biggers if (IS_ENABLED(CONFIG_CRC64_ARCH))
42*067bc871SEric Biggers return ~crc64_nvme_arch(~crc, p, len);
43*067bc871SEric Biggers return ~crc64_nvme_generic(~crc, p, len);
44feb541bfSEric Biggers }
45f3813f4bSKeith Busch
46feba04fdSColy Li #endif /* _LINUX_CRC64_H */
47