Skip to content

Commit f6c3f6f

Browse files
committed
lib/crc64: rename CRC64-Rocksoft to CRC64-NVME
This CRC64 variant comes from the NVME NVM Command Set Specification (https://nvmexpress.org/wp-content/uploads/NVM-Express-NVM-Command-Set-Specification-1.0e-2024.07.29-Ratified.pdf). The "Rocksoft Model CRC Algorithm", published in 1993 and available at https://www.zlib.net/crc_v3.txt, is a generalized CRC algorithm that can calculate any variant of CRC, given a list of parameters such as polynomial, bit order, etc. It is not a CRC variant. The NVME NVM Command Set Specification has a table that gives the "Rocksoft Model Parameters" for the CRC variant it uses. When support for this CRC variant was added to Linux, this table seems to have been misinterpreted as naming the CRC variant the "Rocksoft" CRC. In fact, the table names the CRC variant as the "NVM Express 64b CRC". Most implementations of this CRC variant outside Linux have been calling it CRC64-NVME. Therefore, update Linux to match. While at it, remove the superfluous "update" from the function name, so crc64_rocksoft_update() is now just crc64_nvme(), matching most of the other CRC library functions. Reviewed-by: Ard Biesheuvel <[email protected]> Reviewed-by: "Martin K. Petersen" <[email protected]> Acked-by: Keith Busch <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent 0fcec0b commit f6c3f6f

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

block/t10-pi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static void t10_pi_type1_complete(struct request *rq, unsigned int nr_bytes)
210210

211211
static __be64 ext_pi_crc64(u64 crc, void *data, unsigned int len)
212212
{
213-
return cpu_to_be64(crc64_rocksoft_update(crc, data, len));
213+
return cpu_to_be64(crc64_nvme(crc, data, len));
214214
}
215215

216216
static void ext_pi_crc64_generate(struct blk_integrity_iter *iter,

include/linux/crc64.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@
88
#include <linux/types.h>
99

1010
u64 __pure crc64_be(u64 crc, const void *p, size_t len);
11-
u64 __pure crc64_rocksoft_generic(u64 crc, const void *p, size_t len);
11+
u64 __pure crc64_nvme_generic(u64 crc, const void *p, size_t len);
1212

1313
/**
14-
* crc64_rocksoft_update - Calculate bitwise Rocksoft CRC64
14+
* crc64_nvme - Calculate CRC64-NVME
1515
* @crc: seed value for computation. 0 for a new CRC calculation, or the
1616
* previous crc64 value if computing incrementally.
1717
* @p: pointer to buffer over which CRC64 is run
1818
* @len: length of buffer @p
19+
*
20+
* This computes the CRC64 defined in the NVME NVM Command Set Specification,
21+
* *including the bitwise inversion at the beginning and end*.
1922
*/
20-
static inline u64 crc64_rocksoft_update(u64 crc, const u8 *p, size_t len)
23+
static inline u64 crc64_nvme(u64 crc, const u8 *p, size_t len)
2124
{
22-
return crc64_rocksoft_generic(crc, p, len);
25+
return crc64_nvme_generic(crc, p, len);
2326
}
2427

2528
#endif /* _LINUX_CRC64_H */

lib/crc64.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
* x^24 + x^23 + x^22 + x^21 + x^19 + x^17 + x^13 + x^12 + x^10 + x^9 +
2323
* x^7 + x^4 + x + 1
2424
*
25-
* crc64rocksoft[256] table is from the Rocksoft specification polynomial
26-
* defined as,
25+
* crc64nvmetable[256] uses the CRC64 polynomial from the NVME NVM Command Set
26+
* Specification and uses least-significant-bit first bit order:
2727
*
2828
* x^64 + x^63 + x^61 + x^59 + x^58 + x^56 + x^55 + x^52 + x^49 + x^48 + x^47 +
2929
* x^46 + x^44 + x^41 + x^37 + x^36 + x^34 + x^32 + x^31 + x^28 + x^26 + x^23 +
@@ -63,16 +63,16 @@ u64 __pure crc64_be(u64 crc, const void *p, size_t len)
6363
}
6464
EXPORT_SYMBOL_GPL(crc64_be);
6565

66-
u64 __pure crc64_rocksoft_generic(u64 crc, const void *p, size_t len)
66+
u64 __pure crc64_nvme_generic(u64 crc, const void *p, size_t len)
6767
{
6868
const unsigned char *_p = p;
6969
size_t i;
7070

7171
crc = ~crc;
7272

7373
for (i = 0; i < len; i++)
74-
crc = (crc >> 8) ^ crc64rocksofttable[(crc & 0xff) ^ *_p++];
74+
crc = (crc >> 8) ^ crc64nvmetable[(crc & 0xff) ^ *_p++];
7575

7676
return ~crc;
7777
}
78-
EXPORT_SYMBOL_GPL(crc64_rocksoft_generic);
78+
EXPORT_SYMBOL_GPL(crc64_nvme_generic);

lib/gen_crc64table.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
#include <stdio.h>
1818

1919
#define CRC64_ECMA182_POLY 0x42F0E1EBA9EA3693ULL
20-
#define CRC64_ROCKSOFT_POLY 0x9A6C9329AC4BC9B5ULL
20+
#define CRC64_NVME_POLY 0x9A6C9329AC4BC9B5ULL
2121

2222
static uint64_t crc64_table[256] = {0};
23-
static uint64_t crc64_rocksoft_table[256] = {0};
23+
static uint64_t crc64_nvme_table[256] = {0};
2424

2525
static void generate_reflected_crc64_table(uint64_t table[256], uint64_t poly)
2626
{
@@ -82,14 +82,14 @@ static void print_crc64_tables(void)
8282
printf("static const u64 ____cacheline_aligned crc64table[256] = {\n");
8383
output_table(crc64_table);
8484

85-
printf("\nstatic const u64 ____cacheline_aligned crc64rocksofttable[256] = {\n");
86-
output_table(crc64_rocksoft_table);
85+
printf("\nstatic const u64 ____cacheline_aligned crc64nvmetable[256] = {\n");
86+
output_table(crc64_nvme_table);
8787
}
8888

8989
int main(int argc, char *argv[])
9090
{
9191
generate_crc64_table(crc64_table, CRC64_ECMA182_POLY);
92-
generate_reflected_crc64_table(crc64_rocksoft_table, CRC64_ROCKSOFT_POLY);
92+
generate_reflected_crc64_table(crc64_nvme_table, CRC64_NVME_POLY);
9393
print_crc64_tables();
9494
return 0;
9595
}

0 commit comments

Comments
 (0)