From: David Laight <David.Laight@ACULAB.COM>
To: 'Keith Busch' <kbusch@kernel.org>,
"linux-nvme@lists.infradead.org" <linux-nvme@lists.infradead.org>,
"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
"linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "axboe@kernel.dk" <axboe@kernel.dk>, "hch@lst.de" <hch@lst.de>,
"martin.petersen@oracle.com" <martin.petersen@oracle.com>,
Hannes Reinecke <hare@suse.de>
Subject: RE: [PATCHv4 5/8] lib: add rocksoft model crc64
Date: Fri, 4 Mar 2022 07:53:44 +0000 [thread overview]
Message-ID: <30e059eca211460780442e2ded092722@AcuMS.aculab.com> (raw)
In-Reply-To: <20220303201312.3255347-6-kbusch@kernel.org>
From: Keith Busch
> Sent: 03 March 2022 20:13
>
> The NVM Express specification extended data integrity fields to 64 bits
> using the Rocksoft parameters. Add the poly to the crc64 table
> generation, and provide a generic library routine implementing the
> algorithm.
>
> The Rocksoft 64-bit CRC model parameters are as follows:
> Poly: 0xAD93D23594C93659
> Initial value: 0xFFFFFFFFFFFFFFFF
> Reflected Input: True
> Reflected Output: True
> Xor Final: 0xFFFFFFFFFFFFFFFF
>
> Since this model used reflected bits, the implementation generates the
> reflected table so the result is ordered consistently.
Since the data is processed least significant bit first the
table must be setup slightly differently.
...
> + * crc64rocksoft[256] table is from the Rocksoft specification polynomial
> + * defined as,
> + *
> + * x^64 + x^63 + x^61 + x^59 + x^58 + x^56 + x^55 + x^52 + x^49 + x^48 + x^47 +
> + * x^46 + x^44 + x^41 + x^37 + x^36 + x^34 + x^32 + x^31 + x^28 + x^26 + x^23 +
> + * x^22 + x^19 + x^16 + x^13 + x^12 + x^10 + x^9 + x^6 + x^4 + x^3 + 1
Which matches the Poly: 0xAD93D23594C93659 above.
...
> +#define CRC64_ROCKSOFT_POLY 0x9A6C9329AC4BC9B5ULL
But that value is clearly different.
You really ought to add a comment that each byte of the constant
has to be bit reversed from the polynomial coefficients.
> -static void generate_crc64_table(void)
> +static void generate_reflected_crc64_table(uint64_t table[256], uint64_t poly)
> +{
> + uint64_t i, j, c, crc;
> +
> + for (i = 0; i < 256; i++) {
> + crc = 0ULL;
> + c = i;
> +
> + for (j = 0; j < 8; j++) {
> + if ((crc ^ (c >> j)) & 1)
> + crc = (crc >> 1) ^ poly;
> + else
> + crc >>= 1;
> + }
> + table[i] = crc;
> + }
> +}
That can be speeded up by using the identity:
table[x ^ y] == table[x] ^ table[y]
something like:
crc = poly; /* actually crc(1) */
table[0] = 0;
table[1] = crc;
for (i = 2; i < 8; i++) [
crc = crc & 1 ? (crc >> 1) ^ poly : crc >> 1;
for (j = 0; j < 1u << i; j++)
table[j + (1i << i)] = table[j] ^ crc;
}
I think the same code can be used for a normal MSB first crc
provided both the polynomial and crc(1) are passed in.
OTOH initialisation speed may not matter.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2022-03-04 7:53 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-03 20:13 [PATCHv4 0/8] 64-bit data integrity field support Keith Busch
2022-03-03 20:13 ` [PATCHv4 1/8] block: support pi with extended metadata Keith Busch
2022-03-03 20:13 ` [PATCHv4 2/8] nvme: allow integrity on extended metadata formats Keith Busch
2022-03-03 20:13 ` [PATCHv4 3/8] asm-generic: introduce be48 unaligned accessors Keith Busch
2022-03-03 20:47 ` Bart Van Assche
2022-03-04 1:31 ` David Laight
2022-03-04 2:40 ` Martin K. Petersen
2022-03-04 2:56 ` Keith Busch
2022-03-03 20:13 ` [PATCHv4 4/8] linux/kernel: introduce lower_48_bits function Keith Busch
2022-03-03 20:48 ` Bart Van Assche
2022-03-03 20:13 ` [PATCHv4 5/8] lib: add rocksoft model crc64 Keith Busch
2022-03-04 2:41 ` Martin K. Petersen
2022-03-04 7:53 ` David Laight [this message]
2022-03-04 15:02 ` Keith Busch
2022-03-03 20:13 ` [PATCHv4 6/8] crypto: add rocksoft 64b crc guard tag framework Keith Busch
2022-03-08 20:21 ` Vasily Gorbik
2022-03-08 20:27 ` Keith Busch
2022-03-08 21:46 ` Keith Busch
2022-03-08 22:03 ` Vasily Gorbik
2022-03-09 4:57 ` Eric Biggers
2022-03-09 19:31 ` Keith Busch
2022-03-09 19:49 ` Eric Biggers
2022-03-10 15:39 ` Keith Busch
2022-03-10 18:36 ` Eric Biggers
2022-03-11 20:00 ` Keith Busch
2022-03-03 20:13 ` [PATCHv4 7/8] block: add pi for extended integrity Keith Busch
2022-03-04 2:41 ` Martin K. Petersen
2022-03-03 20:13 ` [PATCHv4 8/8] nvme: add support for enhanced metadata Keith Busch
2022-03-04 2:38 ` Martin K. Petersen
2022-03-07 19:34 ` [PATCHv4 0/8] 64-bit data integrity field support Keith Busch
2022-03-07 19:50 ` Jens Axboe
2022-03-07 19:50 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=30e059eca211460780442e2ded092722@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=axboe@kernel.dk \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=martin.petersen@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox