Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
0002 /* Copyright (C) 2015-2017 Netronome Systems, Inc. */
0003 
0004 #ifndef NFP_CRC32_H
0005 #define NFP_CRC32_H
0006 
0007 #include <linux/crc32.h>
0008 
0009 /**
0010  * crc32_posix_end() - Finalize POSIX CRC32 working state
0011  * @crc:    Current CRC32 working state
0012  * @total_len:  Total length of data that was CRC32'd
0013  *
0014  * Return: Final POSIX CRC32 value
0015  */
0016 static inline u32 crc32_posix_end(u32 crc, size_t total_len)
0017 {
0018     /* Extend with the length of the string. */
0019     while (total_len != 0) {
0020         u8 c = total_len & 0xff;
0021 
0022         crc = crc32_be(crc, &c, 1);
0023         total_len >>= 8;
0024     }
0025 
0026     return ~crc;
0027 }
0028 
0029 static inline u32 crc32_posix(const void *buff, size_t len)
0030 {
0031     return crc32_posix_end(crc32_be(0, buff, len), len);
0032 }
0033 
0034 #endif /* NFP_CRC32_H */