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