diff options
-rw-r--r-- | fs/pstore/ram.c | 26 | ||||
-rw-r--r-- | fs/pstore/ram_core.c | 66 | ||||
-rw-r--r-- | include/linux/pstore_ram.h | 14 |
3 files changed, 64 insertions, 42 deletions
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 288f068740f6..32cbd7c8a90c 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; |
@@ -136,6 +136,7 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, | |||
136 | char **buf, struct pstore_info *psi) | 136 | char **buf, struct pstore_info *psi) |
137 | { | 137 | { |
138 | ssize_t size; | 138 | ssize_t size; |
139 | ssize_t ecc_notice_size; | ||
139 | struct ramoops_context *cxt = psi->data; | 140 | struct ramoops_context *cxt = psi->data; |
140 | struct persistent_ram_zone *prz; | 141 | struct persistent_ram_zone *prz; |
141 | 142 | ||
@@ -156,12 +157,18 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, | |||
156 | time->tv_nsec = 0; | 157 | time->tv_nsec = 0; |
157 | 158 | ||
158 | size = persistent_ram_old_size(prz); | 159 | size = persistent_ram_old_size(prz); |
159 | *buf = kmalloc(size, GFP_KERNEL); | 160 | |
161 | /* ECC correction notice */ | ||
162 | ecc_notice_size = persistent_ram_ecc_string(prz, NULL, 0); | ||
163 | |||
164 | *buf = kmalloc(size + ecc_notice_size + 1, GFP_KERNEL); | ||
160 | if (*buf == NULL) | 165 | if (*buf == NULL) |
161 | return -ENOMEM; | 166 | return -ENOMEM; |
167 | |||
162 | memcpy(*buf, persistent_ram_old(prz), size); | 168 | memcpy(*buf, persistent_ram_old(prz), size); |
169 | persistent_ram_ecc_string(prz, *buf + size, ecc_notice_size + 1); | ||
163 | 170 | ||
164 | return size; | 171 | return size + ecc_notice_size; |
165 | } | 172 | } |
166 | 173 | ||
167 | static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz) | 174 | static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz) |
@@ -323,7 +330,8 @@ static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt, | |||
323 | for (i = 0; i < cxt->max_dump_cnt; i++) { | 330 | for (i = 0; i < cxt->max_dump_cnt; i++) { |
324 | size_t sz = cxt->record_size; | 331 | size_t sz = cxt->record_size; |
325 | 332 | ||
326 | cxt->przs[i] = persistent_ram_new(*paddr, sz, 0, cxt->ecc_size); | 333 | cxt->przs[i] = persistent_ram_new(*paddr, sz, 0, |
334 | &cxt->ecc_info); | ||
327 | if (IS_ERR(cxt->przs[i])) { | 335 | if (IS_ERR(cxt->przs[i])) { |
328 | err = PTR_ERR(cxt->przs[i]); | 336 | err = PTR_ERR(cxt->przs[i]); |
329 | dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n", | 337 | dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n", |
@@ -353,7 +361,7 @@ static int ramoops_init_prz(struct device *dev, struct ramoops_context *cxt, | |||
353 | return -ENOMEM; | 361 | return -ENOMEM; |
354 | } | 362 | } |
355 | 363 | ||
356 | *prz = persistent_ram_new(*paddr, sz, sig, cxt->ecc_size); | 364 | *prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info); |
357 | if (IS_ERR(*prz)) { | 365 | if (IS_ERR(*prz)) { |
358 | int err = PTR_ERR(*prz); | 366 | int err = PTR_ERR(*prz); |
359 | 367 | ||
@@ -407,7 +415,7 @@ static int ramoops_probe(struct platform_device *pdev) | |||
407 | cxt->console_size = pdata->console_size; | 415 | cxt->console_size = pdata->console_size; |
408 | cxt->ftrace_size = pdata->ftrace_size; | 416 | cxt->ftrace_size = pdata->ftrace_size; |
409 | cxt->dump_oops = pdata->dump_oops; | 417 | cxt->dump_oops = pdata->dump_oops; |
410 | cxt->ecc_size = pdata->ecc_size; | 418 | cxt->ecc_info = pdata->ecc_info; |
411 | 419 | ||
412 | paddr = cxt->phys_addr; | 420 | paddr = cxt->phys_addr; |
413 | 421 | ||
@@ -465,9 +473,9 @@ static int ramoops_probe(struct platform_device *pdev) | |||
465 | record_size = pdata->record_size; | 473 | record_size = pdata->record_size; |
466 | dump_oops = pdata->dump_oops; | 474 | dump_oops = pdata->dump_oops; |
467 | 475 | ||
468 | pr_info("attached 0x%lx@0x%llx, ecc: %d\n", | 476 | pr_info("attached 0x%lx@0x%llx, ecc: %d/%d\n", |
469 | cxt->size, (unsigned long long)cxt->phys_addr, | 477 | cxt->size, (unsigned long long)cxt->phys_addr, |
470 | cxt->ecc_size); | 478 | cxt->ecc_info.ecc_size, cxt->ecc_info.block_size); |
471 | 479 | ||
472 | return 0; | 480 | return 0; |
473 | 481 | ||
@@ -539,7 +547,7 @@ static void ramoops_register_dummy(void) | |||
539 | * For backwards compatibility ramoops.ecc=1 means 16 bytes ECC | 547 | * For backwards compatibility ramoops.ecc=1 means 16 bytes ECC |
540 | * (using 1 byte for ECC isn't much of use anyway). | 548 | * (using 1 byte for ECC isn't much of use anyway). |
541 | */ | 549 | */ |
542 | dummy_data->ecc_size = ramoops_ecc == 1 ? 16 : ramoops_ecc; | 550 | dummy_data->ecc_info.ecc_size = ramoops_ecc == 1 ? 16 : ramoops_ecc; |
543 | 551 | ||
544 | dummy = platform_device_register_data(NULL, "ramoops", -1, | 552 | dummy = platform_device_register_data(NULL, "ramoops", -1, |
545 | dummy_data, sizeof(struct ramoops_platform_data)); | 553 | dummy_data, sizeof(struct ramoops_platform_data)); |
diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c index 0306303be372..59337326e288 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,44 +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 | ||
174 | static int persistent_ram_init_ecc(struct persistent_ram_zone *prz, | 174 | static 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_block_size); | 190 | ecc_blocks = DIV_ROUND_UP(prz->buffer_size - prz->ecc_info.ecc_size, |
191 | ecc_total = (ecc_blocks + 1) * prz->ecc_size; | 191 | prz->ecc_info.block_size + |
192 | prz->ecc_info.ecc_size); | ||
193 | ecc_total = (ecc_blocks + 1) * prz->ecc_info.ecc_size; | ||
192 | if (ecc_total >= prz->buffer_size) { | 194 | if (ecc_total >= prz->buffer_size) { |
193 | 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", |
194 | __func__, prz->ecc_size, ecc_total, prz->buffer_size); | 196 | __func__, prz->ecc_info.ecc_size, |
197 | ecc_total, prz->buffer_size); | ||
195 | return -EINVAL; | 198 | return -EINVAL; |
196 | } | 199 | } |
197 | 200 | ||
198 | prz->buffer_size -= ecc_total; | 201 | prz->buffer_size -= ecc_total; |
199 | prz->par_buffer = buffer->data + prz->buffer_size; | 202 | prz->par_buffer = buffer->data + prz->buffer_size; |
200 | 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; | ||
201 | 205 | ||
202 | /* | 206 | /* |
203 | * first consecutive root is 0 | 207 | * first consecutive root is 0 |
204 | * primitive element to generate roots = 1 | 208 | * primitive element to generate roots = 1 |
205 | */ | 209 | */ |
206 | 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); | ||
207 | if (prz->rs_decoder == NULL) { | 212 | if (prz->rs_decoder == NULL) { |
208 | pr_info("persistent_ram: init_rs failed\n"); | 213 | pr_info("persistent_ram: init_rs failed\n"); |
209 | return -EINVAL; | 214 | return -EINVAL; |
@@ -230,6 +235,9 @@ ssize_t persistent_ram_ecc_string(struct persistent_ram_zone *prz, | |||
230 | { | 235 | { |
231 | ssize_t ret; | 236 | ssize_t ret; |
232 | 237 | ||
238 | if (!prz->ecc_info.ecc_size) | ||
239 | return 0; | ||
240 | |||
233 | if (prz->corrected_bytes || prz->bad_blocks) | 241 | if (prz->corrected_bytes || prz->bad_blocks) |
234 | ret = snprintf(str, len, "" | 242 | ret = snprintf(str, len, "" |
235 | "\n%d Corrected bytes, %d unrecoverable blocks\n", | 243 | "\n%d Corrected bytes, %d unrecoverable blocks\n", |
@@ -391,11 +399,11 @@ static int persistent_ram_buffer_map(phys_addr_t start, phys_addr_t size, | |||
391 | } | 399 | } |
392 | 400 | ||
393 | static int persistent_ram_post_init(struct persistent_ram_zone *prz, u32 sig, | 401 | static int persistent_ram_post_init(struct persistent_ram_zone *prz, u32 sig, |
394 | int ecc_size) | 402 | struct persistent_ram_ecc_info *ecc_info) |
395 | { | 403 | { |
396 | int ret; | 404 | int ret; |
397 | 405 | ||
398 | ret = persistent_ram_init_ecc(prz, ecc_size); | 406 | ret = persistent_ram_init_ecc(prz, ecc_info); |
399 | if (ret) | 407 | if (ret) |
400 | return ret; | 408 | return ret; |
401 | 409 | ||
@@ -444,7 +452,7 @@ void persistent_ram_free(struct persistent_ram_zone *prz) | |||
444 | } | 452 | } |
445 | 453 | ||
446 | struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, | 454 | struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, |
447 | u32 sig, int ecc_size) | 455 | u32 sig, struct persistent_ram_ecc_info *ecc_info) |
448 | { | 456 | { |
449 | struct persistent_ram_zone *prz; | 457 | struct persistent_ram_zone *prz; |
450 | int ret = -ENOMEM; | 458 | int ret = -ENOMEM; |
@@ -459,7 +467,7 @@ struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, | |||
459 | if (ret) | 467 | if (ret) |
460 | goto err; | 468 | goto err; |
461 | 469 | ||
462 | ret = persistent_ram_post_init(prz, sig, ecc_size); | 470 | ret = persistent_ram_post_init(prz, sig, ecc_info); |
463 | if (ret) | 471 | if (ret) |
464 | goto err; | 472 | goto err; |
465 | 473 | ||
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 @@ | |||
26 | struct persistent_ram_buffer; | 26 | struct persistent_ram_buffer; |
27 | struct rs_control; | 27 | struct rs_control; |
28 | 28 | ||
29 | struct persistent_ram_ecc_info { | ||
30 | int block_size; | ||
31 | int ecc_size; | ||
32 | int symsize; | ||
33 | int poly; | ||
34 | }; | ||
35 | |||
29 | struct persistent_ram_zone { | 36 | struct 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 | ||
49 | struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size, | 55 | struct 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); |
51 | void persistent_ram_free(struct persistent_ram_zone *prz); | 57 | void persistent_ram_free(struct persistent_ram_zone *prz); |
52 | void persistent_ram_zap(struct persistent_ram_zone *prz); | 58 | void 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 |