Linux Audio

Check our new training course

Loading...
v6.2
  1/* SPDX-License-Identifier: GPL-2.0-or-later */
  2/*
  3 * Copyright (C) 2015 Google, Inc.
  4 *
  5 * Author: Sami Tolvanen <samitolvanen@google.com>
 
 
 
 
 
  6 */
  7
  8#ifndef DM_VERITY_FEC_H
  9#define DM_VERITY_FEC_H
 10
 11#include "dm-verity.h"
 12#include <linux/rslib.h>
 13
 14/* Reed-Solomon(M, N) parameters */
 15#define DM_VERITY_FEC_RSM		255
 16#define DM_VERITY_FEC_MAX_RSN		253
 17#define DM_VERITY_FEC_MIN_RSN		231	/* ~10% space overhead */
 18
 19/* buffers for deinterleaving and decoding */
 20#define DM_VERITY_FEC_BUF_PREALLOC	1	/* buffers to preallocate */
 21#define DM_VERITY_FEC_BUF_RS_BITS	4	/* 1 << RS blocks per buffer */
 22/* we need buffers for at most 1 << block size RS blocks */
 23#define DM_VERITY_FEC_BUF_MAX \
 24	(1 << (PAGE_SHIFT - DM_VERITY_FEC_BUF_RS_BITS))
 25
 26/* maximum recursion level for verity_fec_decode */
 27#define DM_VERITY_FEC_MAX_RECURSION	4
 28
 29#define DM_VERITY_OPT_FEC_DEV		"use_fec_from_device"
 30#define DM_VERITY_OPT_FEC_BLOCKS	"fec_blocks"
 31#define DM_VERITY_OPT_FEC_START		"fec_start"
 32#define DM_VERITY_OPT_FEC_ROOTS		"fec_roots"
 33
 34/* configuration */
 35struct dm_verity_fec {
 36	struct dm_dev *dev;	/* parity data device */
 37	struct dm_bufio_client *data_bufio;	/* for data dev access */
 38	struct dm_bufio_client *bufio;		/* for parity data access */
 39	size_t io_size;		/* IO size for roots */
 40	sector_t start;		/* parity data start in blocks */
 41	sector_t blocks;	/* number of blocks covered */
 42	sector_t rounds;	/* number of interleaving rounds */
 43	sector_t hash_blocks;	/* blocks covered after v->hash_start */
 44	unsigned char roots;	/* number of parity bytes, M-N of RS(M, N) */
 45	unsigned char rsn;	/* N of RS(M, N) */
 46	mempool_t rs_pool;	/* mempool for fio->rs */
 47	mempool_t prealloc_pool;	/* mempool for preallocated buffers */
 48	mempool_t extra_pool;	/* mempool for extra buffers */
 49	mempool_t output_pool;	/* mempool for output */
 50	struct kmem_cache *cache;	/* cache for buffers */
 51};
 52
 53/* per-bio data */
 54struct dm_verity_fec_io {
 55	struct rs_control *rs;	/* Reed-Solomon state */
 56	int erasures[DM_VERITY_FEC_MAX_RSN];	/* erasures for decode_rs8 */
 57	u8 *bufs[DM_VERITY_FEC_BUF_MAX];	/* bufs for deinterleaving */
 58	unsigned nbufs;		/* number of buffers allocated */
 59	u8 *output;		/* buffer for corrected output */
 60	size_t output_pos;
 61	unsigned level;		/* recursion level */
 62};
 63
 64#ifdef CONFIG_DM_VERITY_FEC
 65
 66/* each feature parameter requires a value */
 67#define DM_VERITY_OPTS_FEC	8
 68
 69extern bool verity_fec_is_enabled(struct dm_verity *v);
 70
 71extern int verity_fec_decode(struct dm_verity *v, struct dm_verity_io *io,
 72			     enum verity_block_type type, sector_t block,
 73			     u8 *dest, struct bvec_iter *iter);
 74
 75extern unsigned verity_fec_status_table(struct dm_verity *v, unsigned sz,
 76					char *result, unsigned maxlen);
 77
 78extern void verity_fec_finish_io(struct dm_verity_io *io);
 79extern void verity_fec_init_io(struct dm_verity_io *io);
 80
 81extern bool verity_is_fec_opt_arg(const char *arg_name);
 82extern int verity_fec_parse_opt_args(struct dm_arg_set *as,
 83				     struct dm_verity *v, unsigned *argc,
 84				     const char *arg_name);
 85
 86extern void verity_fec_dtr(struct dm_verity *v);
 87
 88extern int verity_fec_ctr_alloc(struct dm_verity *v);
 89extern int verity_fec_ctr(struct dm_verity *v);
 90
 91#else /* !CONFIG_DM_VERITY_FEC */
 92
 93#define DM_VERITY_OPTS_FEC	0
 94
 95static inline bool verity_fec_is_enabled(struct dm_verity *v)
 96{
 97	return false;
 98}
 99
100static inline int verity_fec_decode(struct dm_verity *v,
101				    struct dm_verity_io *io,
102				    enum verity_block_type type,
103				    sector_t block, u8 *dest,
104				    struct bvec_iter *iter)
105{
106	return -EOPNOTSUPP;
107}
108
109static inline unsigned verity_fec_status_table(struct dm_verity *v,
110					       unsigned sz, char *result,
111					       unsigned maxlen)
112{
113	return sz;
114}
115
116static inline void verity_fec_finish_io(struct dm_verity_io *io)
117{
118}
119
120static inline void verity_fec_init_io(struct dm_verity_io *io)
121{
122}
123
124static inline bool verity_is_fec_opt_arg(const char *arg_name)
125{
126	return false;
127}
128
129static inline int verity_fec_parse_opt_args(struct dm_arg_set *as,
130					    struct dm_verity *v,
131					    unsigned *argc,
132					    const char *arg_name)
133{
134	return -EINVAL;
135}
136
137static inline void verity_fec_dtr(struct dm_verity *v)
138{
139}
140
141static inline int verity_fec_ctr_alloc(struct dm_verity *v)
142{
143	return 0;
144}
145
146static inline int verity_fec_ctr(struct dm_verity *v)
147{
148	return 0;
149}
150
151#endif /* CONFIG_DM_VERITY_FEC */
152
153#endif /* DM_VERITY_FEC_H */
v4.17
 
  1/*
  2 * Copyright (C) 2015 Google, Inc.
  3 *
  4 * Author: Sami Tolvanen <samitolvanen@google.com>
  5 *
  6 * This program is free software; you can redistribute it and/or modify it
  7 * under the terms of the GNU General Public License as published by the Free
  8 * Software Foundation; either version 2 of the License, or (at your option)
  9 * any later version.
 10 */
 11
 12#ifndef DM_VERITY_FEC_H
 13#define DM_VERITY_FEC_H
 14
 15#include "dm-verity.h"
 16#include <linux/rslib.h>
 17
 18/* Reed-Solomon(M, N) parameters */
 19#define DM_VERITY_FEC_RSM		255
 20#define DM_VERITY_FEC_MAX_RSN		253
 21#define DM_VERITY_FEC_MIN_RSN		231	/* ~10% space overhead */
 22
 23/* buffers for deinterleaving and decoding */
 24#define DM_VERITY_FEC_BUF_PREALLOC	1	/* buffers to preallocate */
 25#define DM_VERITY_FEC_BUF_RS_BITS	4	/* 1 << RS blocks per buffer */
 26/* we need buffers for at most 1 << block size RS blocks */
 27#define DM_VERITY_FEC_BUF_MAX \
 28	(1 << (PAGE_SHIFT - DM_VERITY_FEC_BUF_RS_BITS))
 29
 30/* maximum recursion level for verity_fec_decode */
 31#define DM_VERITY_FEC_MAX_RECURSION	4
 32
 33#define DM_VERITY_OPT_FEC_DEV		"use_fec_from_device"
 34#define DM_VERITY_OPT_FEC_BLOCKS	"fec_blocks"
 35#define DM_VERITY_OPT_FEC_START		"fec_start"
 36#define DM_VERITY_OPT_FEC_ROOTS		"fec_roots"
 37
 38/* configuration */
 39struct dm_verity_fec {
 40	struct dm_dev *dev;	/* parity data device */
 41	struct dm_bufio_client *data_bufio;	/* for data dev access */
 42	struct dm_bufio_client *bufio;		/* for parity data access */
 
 43	sector_t start;		/* parity data start in blocks */
 44	sector_t blocks;	/* number of blocks covered */
 45	sector_t rounds;	/* number of interleaving rounds */
 46	sector_t hash_blocks;	/* blocks covered after v->hash_start */
 47	unsigned char roots;	/* number of parity bytes, M-N of RS(M, N) */
 48	unsigned char rsn;	/* N of RS(M, N) */
 49	mempool_t *rs_pool;	/* mempool for fio->rs */
 50	mempool_t *prealloc_pool;	/* mempool for preallocated buffers */
 51	mempool_t *extra_pool;	/* mempool for extra buffers */
 52	mempool_t *output_pool;	/* mempool for output */
 53	struct kmem_cache *cache;	/* cache for buffers */
 54};
 55
 56/* per-bio data */
 57struct dm_verity_fec_io {
 58	struct rs_control *rs;	/* Reed-Solomon state */
 59	int erasures[DM_VERITY_FEC_MAX_RSN];	/* erasures for decode_rs8 */
 60	u8 *bufs[DM_VERITY_FEC_BUF_MAX];	/* bufs for deinterleaving */
 61	unsigned nbufs;		/* number of buffers allocated */
 62	u8 *output;		/* buffer for corrected output */
 63	size_t output_pos;
 64	unsigned level;		/* recursion level */
 65};
 66
 67#ifdef CONFIG_DM_VERITY_FEC
 68
 69/* each feature parameter requires a value */
 70#define DM_VERITY_OPTS_FEC	8
 71
 72extern bool verity_fec_is_enabled(struct dm_verity *v);
 73
 74extern int verity_fec_decode(struct dm_verity *v, struct dm_verity_io *io,
 75			     enum verity_block_type type, sector_t block,
 76			     u8 *dest, struct bvec_iter *iter);
 77
 78extern unsigned verity_fec_status_table(struct dm_verity *v, unsigned sz,
 79					char *result, unsigned maxlen);
 80
 81extern void verity_fec_finish_io(struct dm_verity_io *io);
 82extern void verity_fec_init_io(struct dm_verity_io *io);
 83
 84extern bool verity_is_fec_opt_arg(const char *arg_name);
 85extern int verity_fec_parse_opt_args(struct dm_arg_set *as,
 86				     struct dm_verity *v, unsigned *argc,
 87				     const char *arg_name);
 88
 89extern void verity_fec_dtr(struct dm_verity *v);
 90
 91extern int verity_fec_ctr_alloc(struct dm_verity *v);
 92extern int verity_fec_ctr(struct dm_verity *v);
 93
 94#else /* !CONFIG_DM_VERITY_FEC */
 95
 96#define DM_VERITY_OPTS_FEC	0
 97
 98static inline bool verity_fec_is_enabled(struct dm_verity *v)
 99{
100	return false;
101}
102
103static inline int verity_fec_decode(struct dm_verity *v,
104				    struct dm_verity_io *io,
105				    enum verity_block_type type,
106				    sector_t block, u8 *dest,
107				    struct bvec_iter *iter)
108{
109	return -EOPNOTSUPP;
110}
111
112static inline unsigned verity_fec_status_table(struct dm_verity *v,
113					       unsigned sz, char *result,
114					       unsigned maxlen)
115{
116	return sz;
117}
118
119static inline void verity_fec_finish_io(struct dm_verity_io *io)
120{
121}
122
123static inline void verity_fec_init_io(struct dm_verity_io *io)
124{
125}
126
127static inline bool verity_is_fec_opt_arg(const char *arg_name)
128{
129	return false;
130}
131
132static inline int verity_fec_parse_opt_args(struct dm_arg_set *as,
133					    struct dm_verity *v,
134					    unsigned *argc,
135					    const char *arg_name)
136{
137	return -EINVAL;
138}
139
140static inline void verity_fec_dtr(struct dm_verity *v)
141{
142}
143
144static inline int verity_fec_ctr_alloc(struct dm_verity *v)
145{
146	return 0;
147}
148
149static inline int verity_fec_ctr(struct dm_verity *v)
150{
151	return 0;
152}
153
154#endif /* CONFIG_DM_VERITY_FEC */
155
156#endif /* DM_VERITY_FEC_H */