Commit e303567b authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Jim Harris
Browse files

util/crc16: Add init_crc parameter as seed value to spdk_crc16_t10dif



Add init_crc parameter as seed value to spdk_crc16_t10dif API to generate
a CRC value spanning multiple separate buffers.

This will be necessary for upcoming DIF/DIX patches.

Having init_crc parameter is general, and so change the existing API
without adding seed version of the existing API.

Change-Id: I0ac7919b18013967e41829dcedd3e4e73204d5d6
Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/437204


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent d49402fe
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -6,6 +6,10 @@

A new uuid API `spdk_uuid_copy` was added to make a copy of the source uuid.

An new parameter `init_crc` representing the initial CRC value was added to
`spdk_crc16_t10dif`. The parameter can be used to calculate a CRC value spanning
multiple separate buffers.

### nvme

admin_timeout_ms was added to NVMe controller initialization options, users
+2 −2
Original line number Diff line number Diff line
@@ -564,7 +564,7 @@ fio_extended_lba_setup_pi(struct spdk_fio_qpair *fio_qpair, struct io_u *io_u)
		if (io_u->ddir == DDIR_WRITE) {
			if (fio_qpair->io_flags & SPDK_NVME_IO_FLAGS_PRCHK_GUARD) {
				/* CRC buffer should not include PI */
				crc16 = spdk_crc16_t10dif(io_u->buf + extended_lba_size * i,
				crc16 = spdk_crc16_t10dif(0, io_u->buf + extended_lba_size * i,
							  extended_lba_size - 8);
				to_be16(&pi->guard, crc16);
			}
@@ -601,7 +601,7 @@ fio_extended_lba_verify_pi(struct spdk_fio_qpair *fio_qpair, struct io_u *io_u)

		if (fio_qpair->io_flags & SPDK_NVME_IO_FLAGS_PRCHK_GUARD) {
			/* CRC buffer should not include last 8 bytes of PI */
			crc16 = spdk_crc16_t10dif(io_u->buf + extended_lba_size * i,
			crc16 = spdk_crc16_t10dif(0, io_u->buf + extended_lba_size * i,
						  extended_lba_size - 8);
			to_be16(&guard, crc16);
			if (pi->guard != guard) {
+2 −2
Original line number Diff line number Diff line
@@ -541,7 +541,7 @@ task_extended_lba_setup_pi(struct ns_entry *entry, struct perf_task *task, uint6
		if (is_write) {
			if (entry->io_flags & SPDK_NVME_IO_FLAGS_PRCHK_GUARD) {
				/* CRC buffer should not include PI */
				crc16 = spdk_crc16_t10dif(task->buf + (sector_size + md_size) * i,
				crc16 = spdk_crc16_t10dif(0, task->buf + (sector_size + md_size) * i,
							  sector_size + md_size - 8);
				to_be16(&pi->guard, crc16);
			}
@@ -585,7 +585,7 @@ task_extended_lba_pi_verify(struct ns_entry *entry, struct perf_task *task,

		if (entry->io_flags & SPDK_NVME_IO_FLAGS_PRCHK_GUARD) {
			/* CRC buffer should not include last 8 bytes of PI */
			crc16 = spdk_crc16_t10dif(task->buf + (sector_size + md_size) * i,
			crc16 = spdk_crc16_t10dif(0, task->buf + (sector_size + md_size) * i,
						  sector_size + md_size - 8);
			to_be16(&guard, crc16);
			if (pi->guard != guard) {
+2 −2
Original line number Diff line number Diff line
@@ -53,12 +53,12 @@ extern "C" {
/**
 * Calculate T10-DIF CRC-16 checksum.
 *
 * \param init_crc Initial CRC-16 value.
 * \param buf Data buffer to checksum.
 * \param len Length of buf in bytes.
 * \return CRC-16 value.
 */
uint16_t spdk_crc16_t10dif(const void *buf, size_t len);

uint16_t spdk_crc16_t10dif(uint16_t init_crc, const void *buf, size_t len);
#ifdef __cplusplus
}
#endif
+4 −2
Original line number Diff line number Diff line
@@ -34,14 +34,16 @@
#include "spdk/crc16.h"

uint16_t
spdk_crc16_t10dif(const void *buf, size_t len)
spdk_crc16_t10dif(uint16_t init_crc, const void *buf, size_t len)
{
	uint32_t j, rem = 0;
	uint32_t j, rem;
	const uint8_t *data = (const uint8_t *)buf;
	size_t i;

	uint16_t poly = SPDK_T10DIF_CRC16_POLYNOMIAL;

	rem = init_crc;

	for (i = 0; i < len; i++) {
		rem = rem ^ (data[i] << 8);
		for (j = 0; j < 8; j++) {
Loading