1fa9e406ahrens/*
2fa9e406ahrens * CDDL HEADER START
3fa9e406ahrens *
4fa9e406ahrens * The contents of this file are subject to the terms of the
5ea8dc4beschrock * Common Development and Distribution License (the "License").
6ea8dc4beschrock * You may not use this file except in compliance with the License.
7fa9e406ahrens *
8fa9e406ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e406ahrens * or http://www.opensolaris.org/os/licensing.
10fa9e406ahrens * See the License for the specific language governing permissions
11fa9e406ahrens * and limitations under the License.
12fa9e406ahrens *
13fa9e406ahrens * When distributing Covered Code, include this CDDL HEADER in each
14fa9e406ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e406ahrens * If applicable, add the following below this CDDL HEADER, with the
16fa9e406ahrens * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e406ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e406ahrens *
19fa9e406ahrens * CDDL HEADER END
20fa9e406ahrens */
21fa9e406ahrens/*
22cde58dbMatthew Ahrens * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23770499eDan Kimmel * Copyright (c) 2014, 2016 by Delphix. All rights reserved.
2445818eeMatthew Ahrens * Copyright Saso Kiselkov 2013, All rights reserved.
25fa9e406ahrens */
26fa9e406ahrens
27fa9e406ahrens#ifndef _SYS_ZIO_CHECKSUM_H
28fa9e406ahrens#define	_SYS_ZIO_CHECKSUM_H
29fa9e406ahrens
30fa9e406ahrens#include <sys/zio.h>
3145818eeMatthew Ahrens#include <zfeature_common.h>
32fa9e406ahrens
33fa9e406ahrens#ifdef	__cplusplus
34fa9e406ahrensextern "C" {
35fa9e406ahrens#endif
36fa9e406ahrens
37770499eDan Kimmelstruct abd;
38770499eDan Kimmel
39fa9e406ahrens/*
40fa9e406ahrens * Signature for checksum functions.
41fa9e406ahrens */
42770499eDan Kimmeltypedef void zio_checksum_t(struct abd *, uint64_t size,
4345818eeMatthew Ahrens    const void *ctx_template, zio_cksum_t *zcp);
4445818eeMatthew Ahrenstypedef void *zio_checksum_tmpl_init_t(const zio_cksum_salt_t *salt);
4545818eeMatthew Ahrenstypedef void zio_checksum_tmpl_free_t(void *ctx_template);
4645818eeMatthew Ahrens
4745818eeMatthew Ahrenstypedef enum zio_checksum_flags {
4845818eeMatthew Ahrens	/* Strong enough for metadata? */
4945818eeMatthew Ahrens	ZCHECKSUM_FLAG_METADATA = (1 << 1),
5045818eeMatthew Ahrens	/* ZIO embedded checksum */
5145818eeMatthew Ahrens	ZCHECKSUM_FLAG_EMBEDDED = (1 << 2),
5245818eeMatthew Ahrens	/* Strong enough for dedup (without verification)? */
5345818eeMatthew Ahrens	ZCHECKSUM_FLAG_DEDUP = (1 << 3),
5445818eeMatthew Ahrens	/* Uses salt value */
5545818eeMatthew Ahrens	ZCHECKSUM_FLAG_SALTED = (1 << 4),
5645818eeMatthew Ahrens	/* Strong enough for nopwrite? */
57eb63303Tom Caputi	ZCHECKSUM_FLAG_NOPWRITE = (1 << 5),
5845818eeMatthew Ahrens} zio_checksum_flags_t;
59fa9e406ahrens
60fa9e406ahrens/*
61fa9e406ahrens * Information about each checksum function.
62fa9e406ahrens */
63fa9e406ahrenstypedef struct zio_checksum_info {
6445818eeMatthew Ahrens	/* checksum function for each byteorder */
6545818eeMatthew Ahrens	zio_checksum_t			*ci_func[2];
6645818eeMatthew Ahrens	zio_checksum_tmpl_init_t	*ci_tmpl_init;
6745818eeMatthew Ahrens	zio_checksum_tmpl_free_t	*ci_tmpl_free;
6845818eeMatthew Ahrens	zio_checksum_flags_t		ci_flags;
6945818eeMatthew Ahrens	char				*ci_name;	/* descriptive name */
70fa9e406ahrens} zio_checksum_info_t;
71fa9e406ahrens
7222fe2c8Jonathan Adamstypedef struct zio_bad_cksum {
7322fe2c8Jonathan Adams	zio_cksum_t		zbc_expected;
7422fe2c8Jonathan Adams	zio_cksum_t		zbc_actual;
7522fe2c8Jonathan Adams	const char		*zbc_checksum_name;
7622fe2c8Jonathan Adams	uint8_t			zbc_byteswapped;
7722fe2c8Jonathan Adams	uint8_t			zbc_injected;
7822fe2c8Jonathan Adams	uint8_t			zbc_has_cksum;	/* expected/actual valid */
7922fe2c8Jonathan Adams} zio_bad_cksum_t;
8022fe2c8Jonathan Adams
81fa9e406ahrensextern zio_checksum_info_t zio_checksum_table[ZIO_CHECKSUM_FUNCTIONS];
82fa9e406ahrens
83fa9e406ahrens/*
84fa9e406ahrens * Checksum routines.
85fa9e406ahrens */
86770499eDan Kimmelextern zio_checksum_t abd_checksum_SHA256;
87770499eDan Kimmelextern zio_checksum_t abd_checksum_SHA512_native;
88770499eDan Kimmelextern zio_checksum_t abd_checksum_SHA512_byteswap;
8945818eeMatthew Ahrens
9045818eeMatthew Ahrens/* Skein */
91770499eDan Kimmelextern zio_checksum_t abd_checksum_skein_native;
92770499eDan Kimmelextern zio_checksum_t abd_checksum_skein_byteswap;
93770499eDan Kimmelextern zio_checksum_tmpl_init_t abd_checksum_skein_tmpl_init;
94770499eDan Kimmelextern zio_checksum_tmpl_free_t abd_checksum_skein_tmpl_free;
9545818eeMatthew Ahrens
9645818eeMatthew Ahrens/* Edon-R */
97770499eDan Kimmelextern zio_checksum_t abd_checksum_edonr_native;
98770499eDan Kimmelextern zio_checksum_t abd_checksum_edonr_byteswap;
99770499eDan Kimmelextern zio_checksum_tmpl_init_t abd_checksum_edonr_tmpl_init;
100770499eDan Kimmelextern zio_checksum_tmpl_free_t abd_checksum_edonr_tmpl_free;
101fa9e406ahrens
102dcbf3bdGeorge Wilsonextern int zio_checksum_equal(spa_t *, blkptr_t *, enum zio_checksum,
103dcbf3bdGeorge Wilson    void *, uint64_t, uint64_t, zio_bad_cksum_t *);
104770499eDan Kimmelextern void zio_checksum_compute(zio_t *, enum zio_checksum,
105770499eDan Kimmel    struct abd *, uint64_t);
106eb63303Tom Caputiextern int zio_checksum_error_impl(spa_t *, const blkptr_t *, enum zio_checksum,
107770499eDan Kimmel    struct abd *, uint64_t, uint64_t, zio_bad_cksum_t *);
10822fe2c8Jonathan Adamsextern int zio_checksum_error(zio_t *zio, zio_bad_cksum_t *out);
109cde58dbMatthew Ahrensextern enum zio_checksum spa_dedup_checksum(spa_t *spa);
11045818eeMatthew Ahrensextern void zio_checksum_templates_free(spa_t *spa);
11145818eeMatthew Ahrensextern spa_feature_t zio_checksum_to_feature(enum zio_checksum cksum);
112fa9e406ahrens
113fa9e406ahrens#ifdef	__cplusplus
114fa9e406ahrens}
115fa9e406ahrens#endif
116fa9e406ahrens
117fa9e406ahrens#endif	/* _SYS_ZIO_CHECKSUM_H */
118