aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArve Hjønnevåg <arve@android.com>2012-05-22 19:33:23 -0400
committerAnton Vorontsov <anton@enomsg.org>2013-04-04 00:50:00 -0400
commitc31ad081e8734aab3fb45d2f32e9969994dd076e (patch)
treed4c55b3c6a07b78e6386560cd2f969341c1ae45a
parent422ca8608c49d1e9bfed1c58a1ca448a8a38c0ad (diff)
pstore/ram: Allow specifying ecc parameters in platform data
Allow specifying ecc parameters in platform data Signed-off-by: Arve Hjønnevåg <arve@android.com> [jstultz: Tweaked commit subject & add commit message] Signed-off-by: John Stultz <john.stultz@linaro.org> Acked-by: Kees Cook <keescook@chromium.org> Signed-off-by: Anton Vorontsov <anton@enomsg.org>
-rw-r--r--fs/pstore/ram.c15
-rw-r--r--fs/pstore/ram_core.c64
-rw-r--r--include/linux/pstore_ram.h14
3 files changed, 52 insertions, 41 deletions
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 38babb3a9384..a5ee252c264e 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -83,7 +83,7 @@ struct ramoops_context {
83 size_t console_size; 83 size_t console_size;
84 size_t ftrace_size; 84 size_t ftrace_size;
85 int dump_oops; 85 int dump_oops;
86 int ecc_size; 86 struct persistent_ram_ecc_info ecc_info;
87 unsigned int max_dump_cnt; 87 unsigned int max_dump_cnt;
88 unsigned int dump_write_cnt; 88 unsigned int dump_write_cnt;
89 unsigned int dump_read_cnt; 89 unsigned int dump_read_cnt;
@@ -322,7 +322,8 @@ static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
322 for (i = 0; i < cxt->max_dump_cnt; i++) { 322 for (i = 0; i < cxt->max_dump_cnt; i++) {
323 size_t sz = cxt->record_size; 323 size_t sz = cxt->record_size;
324 324
325 cxt->przs[i] = persistent_ram_new(*paddr, sz, 0, cxt->ecc_size); 325 cxt->przs[i] = persistent_ram_new(*paddr, sz, 0,
326 &cxt->ecc_info);
326 if (IS_ERR(cxt->przs[i])) { 327 if (IS_ERR(cxt->przs[i])) {
327 err = PTR_ERR(cxt->przs[i]); 328 err = PTR_ERR(cxt->przs[i]);
328 dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n", 329 dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n",
@@ -352,7 +353,7 @@ static int ramoops_init_prz(struct device *dev, struct ramoops_context *cxt,
352 return -ENOMEM; 353 return -ENOMEM;
353 } 354 }
354 355
355 *prz = persistent_ram_new(*paddr, sz, sig, cxt->ecc_size); 356 *prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info);
356 if (IS_ERR(*prz)) { 357 if (IS_ERR(*prz)) {
357 int err = PTR_ERR(*prz); 358 int err = PTR_ERR(*prz);
358 359
@@ -406,7 +407,7 @@ static int ramoops_probe(struct platform_device *pdev)
406 cxt->console_size = pdata->console_size; 407 cxt->console_size = pdata->console_size;
407 cxt->ftrace_size = pdata->ftrace_size; 408 cxt->ftrace_size = pdata->ftrace_size;
408 cxt->dump_oops = pdata->dump_oops; 409 cxt->dump_oops = pdata->dump_oops;
409 cxt->ecc_size = pdata->ecc_size; 410 cxt->ecc_info = pdata->ecc_info;
410 411
411 paddr = cxt->phys_addr; 412 paddr = cxt->phys_addr;
412 413
@@ -464,9 +465,9 @@ static int ramoops_probe(struct platform_device *pdev)
464 record_size = pdata->record_size; 465 record_size = pdata->record_size;
465 dump_oops = pdata->dump_oops; 466 dump_oops = pdata->dump_oops;
466 467
467 pr_info("attached 0x%lx@0x%llx, ecc: %d\n", 468 pr_info("attached 0x%lx@0x%llx, ecc: %d/%d\n",
468 cxt->size, (unsigned long long)cxt->phys_addr, 469 cxt->size, (unsigned long long)cxt->phys_addr,
469 cxt->ecc_size); 470 cxt->ecc_info.ecc_size, cxt->ecc_info.block_size);
470 471
471 return 0; 472 return 0;
472 473
@@ -538,7 +539,7 @@ static void ramoops_register_dummy(void)
538 * For backwards compatibility ramoops.ecc=1 means 16 bytes ECC 539 * For backwards compatibility ramoops.ecc=1 means 16 bytes ECC
539 * (using 1 byte for ECC isn't much of use anyway). 540 * (using 1 byte for ECC isn't much of use anyway).
540 */ 541 */
541 dummy_data->ecc_size = ramoops_ecc == 1 ? 16 : ramoops_ecc; 542 dummy_data->ecc_info.ecc_size = ramoops_ecc == 1 ? 16 : ramoops_ecc;
542 543
543 dummy = platform_device_register_data(NULL, "ramoops", -1, 544 dummy = platform_device_register_data(NULL, "ramoops", -1,
544 dummy_data, sizeof(struct ramoops_platform_data)); 545 dummy_data, sizeof(struct ramoops_platform_data));
diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
index e5afa222c213..c6f641c10179 100644
--- a/fs/pstore/ram_core.c
+++ b/fs/pstore/ram_core.c
@@ -82,12 +82,12 @@ static void notrace persistent_ram_encode_rs8(struct persistent_ram_zone *prz,
82 uint8_t *data, size_t len, uint8_t *ecc) 82 uint8_t *data, size_t len, uint8_t *ecc)
83{ 83{
84 int i; 84 int i;
85 uint16_t par[prz->ecc_size]; 85 uint16_t par[prz->ecc_info.ecc_size];
86 86
87 /* Initialize the parity buffer */ 87 /* Initialize the parity buffer */
88 memset(par, 0, sizeof(par)); 88 memset(par, 0, sizeof(par));
89 encode_rs8(prz->rs_decoder, data, len, par, 0); 89 encode_rs8(prz->rs_decoder, data, len, par, 0);
90 for (i = 0; i < prz->ecc_size; i++) 90 for (i = 0; i < prz->ecc_info.ecc_size; i++)
91 ecc[i] = par[i]; 91 ecc[i] = par[i];
92} 92}
93 93
@@ -95,9 +95,9 @@ static int persistent_ram_decode_rs8(struct persistent_ram_zone *prz,
95 void *data, size_t len, uint8_t *ecc) 95 void *data, size_t len, uint8_t *ecc)
96{ 96{
97 int i; 97 int i;
98 uint16_t par[prz->ecc_size]; 98 uint16_t par[prz->ecc_info.ecc_size];
99 99
100 for (i = 0; i < prz->ecc_size; i++) 100 for (i = 0; i < prz->ecc_info.ecc_size; i++)
101 par[i] = ecc[i]; 101 par[i] = ecc[i];
102 return decode_rs8(prz->rs_decoder, data, par, len, 102 return decode_rs8(prz->rs_decoder, data, par, len,
103 NULL, 0, NULL, 0, NULL); 103 NULL, 0, NULL, 0, NULL);
@@ -110,15 +110,15 @@ static void notrace persistent_ram_update_ecc(struct persistent_ram_zone *prz,
110 uint8_t *buffer_end = buffer->data + prz->buffer_size; 110 uint8_t *buffer_end = buffer->data + prz->buffer_size;
111 uint8_t *block; 111 uint8_t *block;
112 uint8_t *par; 112 uint8_t *par;
113 int ecc_block_size = prz->ecc_block_size; 113 int ecc_block_size = prz->ecc_info.block_size;
114 int ecc_size = prz->ecc_size; 114 int ecc_size = prz->ecc_info.ecc_size;
115 int size = prz->ecc_block_size; 115 int size = ecc_block_size;
116 116
117 if (!prz->ecc_size) 117 if (!ecc_size)
118 return; 118 return;
119 119
120 block = buffer->data + (start & ~(ecc_block_size - 1)); 120 block = buffer->data + (start & ~(ecc_block_size - 1));
121 par = prz->par_buffer + (start / ecc_block_size) * prz->ecc_size; 121 par = prz->par_buffer + (start / ecc_block_size) * ecc_size;
122 122
123 do { 123 do {
124 if (block + ecc_block_size > buffer_end) 124 if (block + ecc_block_size > buffer_end)
@@ -133,7 +133,7 @@ static void persistent_ram_update_header_ecc(struct persistent_ram_zone *prz)
133{ 133{
134 struct persistent_ram_buffer *buffer = prz->buffer; 134 struct persistent_ram_buffer *buffer = prz->buffer;
135 135
136 if (!prz->ecc_size) 136 if (!prz->ecc_info.ecc_size)
137 return; 137 return;
138 138
139 persistent_ram_encode_rs8(prz, (uint8_t *)buffer, sizeof(*buffer), 139 persistent_ram_encode_rs8(prz, (uint8_t *)buffer, sizeof(*buffer),
@@ -146,14 +146,14 @@ static void persistent_ram_ecc_old(struct persistent_ram_zone *prz)
146 uint8_t *block; 146 uint8_t *block;
147 uint8_t *par; 147 uint8_t *par;
148 148
149 if (!prz->ecc_size) 149 if (!prz->ecc_info.ecc_size)
150 return; 150 return;
151 151
152 block = buffer->data; 152 block = buffer->data;
153 par = prz->par_buffer; 153 par = prz->par_buffer;
154 while (block < buffer->data + buffer_size(prz)) { 154 while (block < buffer->data + buffer_size(prz)) {
155 int numerr; 155 int numerr;
156 int size = prz->ecc_block_size; 156 int size = prz->ecc_info.block_size;
157 if (block + size > buffer->data + prz->buffer_size) 157 if (block + size > buffer->data + prz->buffer_size)
158 size = buffer->data + prz->buffer_size - block; 158 size = buffer->data + prz->buffer_size - block;
159 numerr = persistent_ram_decode_rs8(prz, block, size, par); 159 numerr = persistent_ram_decode_rs8(prz, block, size, par);
@@ -166,45 +166,49 @@ static void persistent_ram_ecc_old(struct persistent_ram_zone *prz)
166 block); 166 block);
167 prz->bad_blocks++; 167 prz->bad_blocks++;
168 } 168 }
169 block += prz->ecc_block_size; 169 block += prz->ecc_info.block_size;
170 par += prz->ecc_size; 170 par += prz->ecc_info.ecc_size;
171 } 171 }
172} 172}
173 173
174static int persistent_ram_init_ecc(struct persistent_ram_zone *prz, 174static int persistent_ram_init_ecc(struct persistent_ram_zone *prz,
175 int ecc_size) 175 struct persistent_ram_ecc_info *ecc_info)
176{ 176{
177 int numerr; 177 int numerr;
178 struct persistent_ram_buffer *buffer = prz->buffer; 178 struct persistent_ram_buffer *buffer = prz->buffer;
179 int ecc_blocks; 179 int ecc_blocks;
180 size_t ecc_total; 180 size_t ecc_total;
181 int ecc_symsize = 8;
182 int ecc_poly = 0x11d;
183 181
184 if (!ecc_size) 182 if (!ecc_info || !ecc_info->ecc_size)
185 return 0; 183 return 0;
186 184
187 prz->ecc_block_size = 128; 185 prz->ecc_info.block_size = ecc_info->block_size ?: 128;
188 prz->ecc_size = ecc_size; 186 prz->ecc_info.ecc_size = ecc_info->ecc_size ?: 16;
187 prz->ecc_info.symsize = ecc_info->symsize ?: 8;
188 prz->ecc_info.poly = ecc_info->poly ?: 0x11d;
189 189
190 ecc_blocks = DIV_ROUND_UP(prz->buffer_size - prz->ecc_size, 190 ecc_blocks = DIV_ROUND_UP(prz->buffer_size - prz->ecc_info.ecc_size,
191 prz->ecc_block_size + prz->ecc_size); 191 prz->ecc_info.block_size +
192 ecc_total = (ecc_blocks + 1) * prz->ecc_size; 192 prz->ecc_info.ecc_size);
193 ecc_total = (ecc_blocks + 1) * prz->ecc_info.ecc_size;
193 if (ecc_total >= prz->buffer_size) { 194 if (ecc_total >= prz->buffer_size) {
194 pr_err("%s: invalid ecc_size %u (total %zu, buffer size %zu)\n", 195 pr_err("%s: invalid ecc_size %u (total %zu, buffer size %zu)\n",
195 __func__, prz->ecc_size, ecc_total, prz->buffer_size); 196 __func__, prz->ecc_info.ecc_size,
197 ecc_total, prz->buffer_size);
196 return -EINVAL; 198 return -EINVAL;
197 } 199 }
198 200
199 prz->buffer_size -= ecc_total; 201 prz->buffer_size -= ecc_total;
200 prz->par_buffer = buffer->data + prz->buffer_size; 202 prz->par_buffer = buffer->data + prz->buffer_size;
201 prz->par_header = prz->par_buffer + ecc_blocks * prz->ecc_size; 203 prz->par_header = prz->par_buffer +
204 ecc_blocks * prz->ecc_info.ecc_size;
202 205
203 /* 206 /*
204 * first consecutive root is 0 207 * first consecutive root is 0
205 * primitive element to generate roots = 1 208 * primitive element to generate roots = 1
206 */ 209 */
207 prz->rs_decoder = init_rs(ecc_symsize, ecc_poly, 0, 1, prz->ecc_size); 210 prz->rs_decoder = init_rs(prz->ecc_info.symsize, prz->ecc_info.poly,
211 0, 1, prz->ecc_info.ecc_size);
208 if (prz->rs_decoder == NULL) { 212 if (prz->rs_decoder == NULL) {
209 pr_info("persistent_ram: init_rs failed\n"); 213 pr_info("persistent_ram: init_rs failed\n");
210 return -EINVAL; 214 return -EINVAL;
@@ -392,11 +396,11 @@ static int persistent_ram_buffer_map(phys_addr_t start, phys_addr_t size,
392} 396}
393 397
394static int persistent_ram_post_init(struct persistent_ram_zone *prz, u32 sig, 398static int persistent_ram_post_init(struct persistent_ram_zone *prz, u32 sig,
395 int ecc_size) 399 struct persistent_ram_ecc_info *ecc_info)
396{ 400{
397 int ret; 401 int ret;
398 402
399 ret = persistent_ram_init_ecc(prz, ecc_size); 403 ret = persistent_ram_init_ecc(prz, ecc_info);
400 if (ret) 404 if (ret)
401 return ret; 405 return ret;
402 406
@@ -445,7 +449,7 @@ void persistent_ram_free(struct persistent_ram_zone *prz)
445} 449}
446 450
447struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, 451struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
448 u32 sig, int ecc_size) 452 u32 sig, struct persistent_ram_ecc_info *ecc_info)
449{ 453{
450 struct persistent_ram_zone *prz; 454 struct persistent_ram_zone *prz;
451 int ret = -ENOMEM; 455 int ret = -ENOMEM;
@@ -460,7 +464,7 @@ struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
460 if (ret) 464 if (ret)
461 goto err; 465 goto err;
462 466
463 ret = persistent_ram_post_init(prz, sig, ecc_size); 467 ret = persistent_ram_post_init(prz, sig, ecc_info);
464 if (ret) 468 if (ret)
465 goto err; 469 goto err;
466 470
diff --git a/include/linux/pstore_ram.h b/include/linux/pstore_ram.h
index cb6ab5feab67..9974975d40db 100644
--- a/include/linux/pstore_ram.h
+++ b/include/linux/pstore_ram.h
@@ -26,6 +26,13 @@
26struct persistent_ram_buffer; 26struct persistent_ram_buffer;
27struct rs_control; 27struct rs_control;
28 28
29struct persistent_ram_ecc_info {
30 int block_size;
31 int ecc_size;
32 int symsize;
33 int poly;
34};
35
29struct persistent_ram_zone { 36struct persistent_ram_zone {
30 phys_addr_t paddr; 37 phys_addr_t paddr;
31 size_t size; 38 size_t size;
@@ -39,15 +46,14 @@ struct persistent_ram_zone {
39 struct rs_control *rs_decoder; 46 struct rs_control *rs_decoder;
40 int corrected_bytes; 47 int corrected_bytes;
41 int bad_blocks; 48 int bad_blocks;
42 int ecc_block_size; 49 struct persistent_ram_ecc_info ecc_info;
43 int ecc_size;
44 50
45 char *old_log; 51 char *old_log;
46 size_t old_log_size; 52 size_t old_log_size;
47}; 53};
48 54
49struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, 55struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
50 u32 sig, int ecc_size); 56 u32 sig, struct persistent_ram_ecc_info *ecc_info);
51void persistent_ram_free(struct persistent_ram_zone *prz); 57void persistent_ram_free(struct persistent_ram_zone *prz);
52void persistent_ram_zap(struct persistent_ram_zone *prz); 58void persistent_ram_zap(struct persistent_ram_zone *prz);
53 59
@@ -74,7 +80,7 @@ struct ramoops_platform_data {
74 unsigned long console_size; 80 unsigned long console_size;
75 unsigned long ftrace_size; 81 unsigned long ftrace_size;
76 int dump_oops; 82 int dump_oops;
77 int ecc_size; 83 struct persistent_ram_ecc_info ecc_info;
78}; 84};
79 85
80#endif 86#endif