]> git.proxmox.com Git - ceph.git/blob - ceph/src/isa-l/include/crc.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / isa-l / include / crc.h
1 /**********************************************************************
2 Copyright(c) 2011-2015 Intel Corporation All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions
6 are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in
11 the documentation and/or other materials provided with the
12 distribution.
13 * Neither the name of Intel Corporation nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 **********************************************************************/
29
30
31 /**
32 * @file crc.h
33 * @brief CRC functions.
34 */
35
36
37 #ifndef _CRC_H_
38 #define _CRC_H_
39
40 #include <stdint.h>
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46
47 /* Multi-binary functions */
48
49 /**
50 * @brief Generate CRC from the T10 standard, runs appropriate version.
51 *
52 * This function determines what instruction sets are enabled and
53 * selects the appropriate version at runtime.
54 *
55 * @returns 16 bit CRC
56 */
57 uint16_t crc16_t10dif(
58 uint16_t init_crc, //!< initial CRC value, 16 bits
59 const unsigned char *buf, //!< buffer to calculate CRC on
60 uint64_t len //!< buffer length in bytes (64-bit data)
61 );
62
63
64 /**
65 * @brief Generate CRC from the IEEE standard, runs appropriate version.
66 *
67 * This function determines what instruction sets are enabled and
68 * selects the appropriate version at runtime.
69 *
70 * @returns 32 bit CRC
71 */
72
73 uint32_t crc32_ieee(
74 uint32_t init_crc, //!< initial CRC value, 32 bits
75 const unsigned char *buf, //!< buffer to calculate CRC on
76 uint64_t len //!< buffer length in bytes (64-bit data)
77 );
78
79
80 /**
81 * @brief ISCSI CRC function, runs appropriate version.
82 *
83 * This function determines what instruction sets are enabled and
84 * selects the appropriate version at runtime.
85 *
86 * @returns 32 bit CRC
87 */
88 unsigned int crc32_iscsi(
89 unsigned char *buffer, //!< buffer to calculate CRC on
90 int len, //!< buffer length in bytes
91 unsigned int init_crc //!< initial CRC value
92 );
93
94
95 /* Base functions */
96
97 /**
98 * @brief ISCSI CRC function, baseline version
99 * @returns 32 bit CRC
100 */
101 unsigned int crc32_iscsi_base(
102 unsigned char *buffer, //!< buffer to calculate CRC on
103 int len, //!< buffer length in bytes
104 unsigned int crc_init //!< initial CRC value
105 );
106
107
108 /**
109 * @brief Generate CRC from the T10 standard, runs baseline version
110 * @returns 16 bit CRC
111 */
112 uint16_t crc16_t10dif_base(
113 uint16_t seed, //!< initial CRC value, 16 bits
114 uint8_t *buf, //!< buffer to calculate CRC on
115 uint64_t len //!< buffer length in bytes (64-bit data)
116 );
117
118
119 /**
120 * @brief Generate CRC from the IEEE standard, runs baseline version
121 * @returns 32 bit CRC
122 */
123 uint32_t crc32_ieee_base(
124 uint32_t seed, //!< initial CRC value, 32 bits
125 uint8_t *buf, //!< buffer to calculate CRC on
126 uint64_t len //!< buffer length in bytes (64-bit data)
127 );
128
129
130 #ifdef __cplusplus
131 }
132 #endif
133
134 #endif // _CRC_H_