include/spd_bin.h: Add SPD IO layer
[coreboot2.git] / src / include / crc_byte.h
blob85b7221053a93120f511fc9a9608b7481a597f32
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #ifndef CRC_BYTE_H
4 #define CRC_BYTE_H
6 #include <stddef.h>
7 #include <stdint.h>
9 /* This function is used to calculate crc7 byte by byte, with polynomial
10 * x^7 + x^3 + 1.
12 * prev_crc: old crc result (0 for first)
13 * data: new byte
14 * return value: new crc result
16 uint8_t crc7_byte(uint8_t prev_crc, uint8_t data);
18 /* This function is used to calculate crc16 byte by byte, with polynomial
19 * x^16 + x^12 + x^5 + 1.
21 * prev_crc: old crc result (0 for first)
22 * data: new byte
23 * return value: new crc result
25 uint16_t crc16_byte(uint16_t prev_crc, uint8_t data);
27 /* This function is used to calculate crc32 byte by byte, with polynomial
28 * x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 +
29 * x^5 + x^4 + x^2 + x + 1
31 * prev_crc: old crc result (0 for first)
32 * data: new byte
33 * return value: new crc result
35 uint32_t crc32_byte(uint32_t prev_crc, uint8_t data);
37 #define CRC(buf, size, crc_func) ({ \
38 const uint8_t *_crc_local_buf = (const uint8_t *)buf; \
39 size_t _crc_local_size = size; \
40 __typeof__(crc_func(0, 0)) _crc_local_result = 0; \
41 while (_crc_local_size--) { \
42 _crc_local_result = crc_func(_crc_local_result, *_crc_local_buf++); \
43 } \
44 _crc_local_result; \
47 #endif /* CRC_BYTE_H */