1
2
3
4
5
6
7
8
9
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
19#define DM_VERITY_FEC_RSM 255
20#define DM_VERITY_FEC_MAX_RSN 253
21#define DM_VERITY_FEC_MIN_RSN 231
22
23
24#define DM_VERITY_FEC_BUF_PREALLOC 1
25#define DM_VERITY_FEC_BUF_RS_BITS 4
26
27#define DM_VERITY_FEC_BUF_MAX \
28 (1 << (PAGE_SHIFT - DM_VERITY_FEC_BUF_RS_BITS))
29
30#define DM_VERITY_OPT_FEC_DEV "use_fec_from_device"
31#define DM_VERITY_OPT_FEC_BLOCKS "fec_blocks"
32#define DM_VERITY_OPT_FEC_START "fec_start"
33#define DM_VERITY_OPT_FEC_ROOTS "fec_roots"
34
35
36struct dm_verity_fec {
37 struct dm_dev *dev;
38 struct dm_bufio_client *data_bufio;
39 struct dm_bufio_client *bufio;
40 sector_t start;
41 sector_t blocks;
42 sector_t rounds;
43 sector_t hash_blocks;
44 unsigned char roots;
45 unsigned char rsn;
46 mempool_t *rs_pool;
47 mempool_t *prealloc_pool;
48 mempool_t *extra_pool;
49 mempool_t *output_pool;
50 struct kmem_cache *cache;
51};
52
53
54struct dm_verity_fec_io {
55 struct rs_control *rs;
56 int erasures[DM_VERITY_FEC_MAX_RSN];
57 u8 *bufs[DM_VERITY_FEC_BUF_MAX];
58 unsigned nbufs;
59 u8 *output;
60 size_t output_pos;
61};
62
63#ifdef CONFIG_DM_VERITY_FEC
64
65
66#define DM_VERITY_OPTS_FEC 8
67
68extern bool verity_fec_is_enabled(struct dm_verity *v);
69
70extern int verity_fec_decode(struct dm_verity *v, struct dm_verity_io *io,
71 enum verity_block_type type, sector_t block,
72 u8 *dest, struct bvec_iter *iter);
73
74extern unsigned verity_fec_status_table(struct dm_verity *v, unsigned sz,
75 char *result, unsigned maxlen);
76
77extern void verity_fec_finish_io(struct dm_verity_io *io);
78extern void verity_fec_init_io(struct dm_verity_io *io);
79
80extern bool verity_is_fec_opt_arg(const char *arg_name);
81extern int verity_fec_parse_opt_args(struct dm_arg_set *as,
82 struct dm_verity *v, unsigned *argc,
83 const char *arg_name);
84
85extern void verity_fec_dtr(struct dm_verity *v);
86
87extern int verity_fec_ctr_alloc(struct dm_verity *v);
88extern int verity_fec_ctr(struct dm_verity *v);
89
90#else
91
92#define DM_VERITY_OPTS_FEC 0
93
94static inline bool verity_fec_is_enabled(struct dm_verity *v)
95{
96 return false;
97}
98
99static inline int verity_fec_decode(struct dm_verity *v,
100 struct dm_verity_io *io,
101 enum verity_block_type type,
102 sector_t block, u8 *dest,
103 struct bvec_iter *iter)
104{
105 return -EOPNOTSUPP;
106}
107
108static inline unsigned verity_fec_status_table(struct dm_verity *v,
109 unsigned sz, char *result,
110 unsigned maxlen)
111{
112 return sz;
113}
114
115static inline void verity_fec_finish_io(struct dm_verity_io *io)
116{
117}
118
119static inline void verity_fec_init_io(struct dm_verity_io *io)
120{
121}
122
123static inline bool verity_is_fec_opt_arg(const char *arg_name)
124{
125 return false;
126}
127
128static inline int verity_fec_parse_opt_args(struct dm_arg_set *as,
129 struct dm_verity *v,
130 unsigned *argc,
131 const char *arg_name)
132{
133 return -EINVAL;
134}
135
136static inline void verity_fec_dtr(struct dm_verity *v)
137{
138}
139
140static inline int verity_fec_ctr_alloc(struct dm_verity *v)
141{
142 return 0;
143}
144
145static inline int verity_fec_ctr(struct dm_verity *v)
146{
147 return 0;
148}
149
150#endif
151
152#endif
153