Lines Matching +full:no +full:- +full:dump +full:- +full:oops
1 // SPDX-License-Identifier: GPL-2.0-only
3 * MTD Oops/Panic logger
31 "record size for MTD OOPS pages in bytes (default 4096)");
41 "set to 1 to dump oopses, 0 to only dump panics (default 1)");
53 struct kmsg_dumper dump; member
70 set_bit(page, cxt->oops_page_used); in mark_page_used()
75 clear_bit(page, cxt->oops_page_used); in mark_page_unused()
80 return test_bit(page, cxt->oops_page_used); in page_is_used()
85 struct mtd_info *mtd = cxt->mtd; in mtdoops_erase_block()
86 u32 start_page_offset = mtd_div_by_eb(offset, mtd) * mtd->erasesize; in mtdoops_erase_block()
88 u32 erase_pages = mtd->erasesize / record_size; in mtdoops_erase_block()
94 erase.len = mtd->erasesize; in mtdoops_erase_block()
113 struct mtd_info *mtd = cxt->mtd; in mtdoops_erase()
120 mod = (cxt->nextpage * record_size) % mtd->erasesize; in mtdoops_erase()
122 cxt->nextpage = cxt->nextpage + ((mtd->erasesize - mod) / record_size); in mtdoops_erase()
123 if (cxt->nextpage >= cxt->oops_pages) in mtdoops_erase()
124 cxt->nextpage = 0; in mtdoops_erase()
127 while ((ret = mtd_block_isbad(mtd, cxt->nextpage * record_size)) > 0) { in mtdoops_erase()
130 cxt->nextpage * record_size); in mtdoops_erase()
132 cxt->nextpage = cxt->nextpage + (mtd->erasesize / record_size); in mtdoops_erase()
133 if (cxt->nextpage >= cxt->oops_pages) in mtdoops_erase()
134 cxt->nextpage = 0; in mtdoops_erase()
135 if (i == cxt->oops_pages / (mtd->erasesize / record_size)) { in mtdoops_erase()
146 for (j = 0, ret = -1; (j < 3) && (ret < 0); j++) in mtdoops_erase()
147 ret = mtdoops_erase_block(cxt, cxt->nextpage * record_size); in mtdoops_erase()
151 cxt->nextpage, cxt->nextcount); in mtdoops_erase()
155 if (ret == -EIO) { in mtdoops_erase()
156 ret = mtd_block_markbad(mtd, cxt->nextpage * record_size); in mtdoops_erase()
157 if (ret < 0 && ret != -EOPNOTSUPP) { in mtdoops_erase()
165 /* Scheduled work - when we can't proceed without erasing a block */
175 cxt->nextpage++; in mtdoops_inc_counter()
176 if (cxt->nextpage >= cxt->oops_pages) in mtdoops_inc_counter()
177 cxt->nextpage = 0; in mtdoops_inc_counter()
178 cxt->nextcount++; in mtdoops_inc_counter()
179 if (cxt->nextcount == 0xffffffff) in mtdoops_inc_counter()
180 cxt->nextcount = 0; in mtdoops_inc_counter()
182 if (page_is_used(cxt, cxt->nextpage)) { in mtdoops_inc_counter()
184 cxt->nextpage, cxt->nextcount, in mtdoops_inc_counter()
191 schedule_work(&cxt->work_erase); in mtdoops_inc_counter()
194 pr_debug("ready %d, %d (no erase)\n", in mtdoops_inc_counter()
195 cxt->nextpage, cxt->nextcount); in mtdoops_inc_counter()
201 struct mtd_info *mtd = cxt->mtd; in mtdoops_write()
206 if (test_and_set_bit(0, &cxt->oops_buf_busy)) in mtdoops_write()
210 hdr = (struct mtdoops_hdr *)cxt->oops_buf; in mtdoops_write()
211 hdr->seq = cxt->nextcount; in mtdoops_write()
212 hdr->magic = MTDOOPS_KERNMSG_MAGIC_v2; in mtdoops_write()
213 hdr->timestamp = ktime_get_real(); in mtdoops_write()
216 ret = mtd_panic_write(mtd, cxt->nextpage * record_size, in mtdoops_write()
217 record_size, &retlen, cxt->oops_buf); in mtdoops_write()
218 if (ret == -EOPNOTSUPP) { in mtdoops_write()
223 ret = mtd_write(mtd, cxt->nextpage * record_size, in mtdoops_write()
224 record_size, &retlen, cxt->oops_buf); in mtdoops_write()
228 cxt->nextpage * record_size, retlen, record_size, ret); in mtdoops_write()
229 mark_page_used(cxt, cxt->nextpage); in mtdoops_write()
230 memset(cxt->oops_buf, 0xff, record_size); in mtdoops_write()
234 clear_bit(0, &cxt->oops_buf_busy); in mtdoops_write()
247 struct mtd_info *mtd = cxt->mtd; in find_next_position()
253 for (page = 0; page < cxt->oops_pages; page++) { in find_next_position()
289 cxt->nextpage = cxt->oops_pages - 1; in find_next_position()
290 cxt->nextcount = 0; in find_next_position()
293 cxt->nextpage = maxpos; in find_next_position()
294 cxt->nextcount = maxcount; in find_next_position()
304 struct mtdoops_context, dump); in mtdoops_do_dump()
307 /* Only dump oopses if dump_oops is set */ in mtdoops_do_dump()
308 if (detail->reason == KMSG_DUMP_OOPS && !dump_oops) in mtdoops_do_dump()
313 if (test_and_set_bit(0, &cxt->oops_buf_busy)) in mtdoops_do_dump()
316 cxt->oops_buf + sizeof(struct mtdoops_hdr), in mtdoops_do_dump()
317 record_size - sizeof(struct mtdoops_hdr), NULL); in mtdoops_do_dump()
318 clear_bit(0, &cxt->oops_buf_busy); in mtdoops_do_dump()
320 if (detail->reason != KMSG_DUMP_OOPS) { in mtdoops_do_dump()
325 schedule_work(&cxt->work_write); in mtdoops_do_dump()
332 u64 mtdoops_pages = div_u64(mtd->size, record_size); in mtdoops_notify_add()
335 if (!strcmp(mtd->name, mtddev)) in mtdoops_notify_add()
336 cxt->mtd_index = mtd->index; in mtdoops_notify_add()
338 if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0) in mtdoops_notify_add()
341 if (mtd->size < mtd->erasesize * 2) { in mtdoops_notify_add()
343 mtd->index); in mtdoops_notify_add()
346 if (mtd->erasesize < record_size) { in mtdoops_notify_add()
348 mtd->index); in mtdoops_notify_add()
351 if (mtd->size > MTDOOPS_MAX_MTD_SIZE) { in mtdoops_notify_add()
353 mtd->index, MTDOOPS_MAX_MTD_SIZE / 1024 / 1024); in mtdoops_notify_add()
358 cxt->oops_page_used = in mtdoops_notify_add()
362 if (!cxt->oops_page_used) { in mtdoops_notify_add()
367 cxt->dump.max_reason = KMSG_DUMP_OOPS; in mtdoops_notify_add()
368 cxt->dump.dump = mtdoops_do_dump; in mtdoops_notify_add()
369 err = kmsg_dump_register(&cxt->dump); in mtdoops_notify_add()
372 vfree(cxt->oops_page_used); in mtdoops_notify_add()
373 cxt->oops_page_used = NULL; in mtdoops_notify_add()
377 cxt->mtd = mtd; in mtdoops_notify_add()
378 cxt->oops_pages = (int)mtd->size / record_size; in mtdoops_notify_add()
380 pr_info("Attached to MTD device %d\n", mtd->index); in mtdoops_notify_add()
387 if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0) in mtdoops_notify_remove()
390 if (kmsg_dump_unregister(&cxt->dump) < 0) in mtdoops_notify_remove()
393 cxt->mtd = NULL; in mtdoops_notify_remove()
394 flush_work(&cxt->work_erase); in mtdoops_notify_remove()
395 flush_work(&cxt->work_write); in mtdoops_notify_remove()
412 return -EINVAL; in mtdoops_init()
416 return -EINVAL; in mtdoops_init()
420 return -EINVAL; in mtdoops_init()
424 cxt->mtd_index = -1; in mtdoops_init()
427 cxt->mtd_index = mtd_index; in mtdoops_init()
429 cxt->oops_buf = vmalloc(record_size); in mtdoops_init()
430 if (!cxt->oops_buf) in mtdoops_init()
431 return -ENOMEM; in mtdoops_init()
432 memset(cxt->oops_buf, 0xff, record_size); in mtdoops_init()
433 cxt->oops_buf_busy = 0; in mtdoops_init()
435 INIT_WORK(&cxt->work_erase, mtdoops_workfunc_erase); in mtdoops_init()
436 INIT_WORK(&cxt->work_write, mtdoops_workfunc_write); in mtdoops_init()
447 vfree(cxt->oops_buf); in mtdoops_exit()
448 vfree(cxt->oops_page_used); in mtdoops_exit()
457 MODULE_DESCRIPTION("MTD Oops/Panic console logger/driver");