Lines Matching refs:cxt
72 static void mark_page_used(struct mtdoops_context *cxt, int page) in mark_page_used() argument
74 set_bit(page, cxt->oops_page_used); in mark_page_used()
77 static void mark_page_unused(struct mtdoops_context *cxt, int page) in mark_page_unused() argument
79 clear_bit(page, cxt->oops_page_used); in mark_page_unused()
82 static int page_is_used(struct mtdoops_context *cxt, int page) in page_is_used() argument
84 return test_bit(page, cxt->oops_page_used); in page_is_used()
87 static int mtdoops_erase_block(struct mtdoops_context *cxt, int offset) in mtdoops_erase_block() argument
89 struct mtd_info *mtd = cxt->mtd; in mtdoops_erase_block()
110 mark_page_unused(cxt, page); in mtdoops_erase_block()
115 static void mtdoops_inc_counter(struct mtdoops_context *cxt) in mtdoops_inc_counter() argument
117 cxt->nextpage++; in mtdoops_inc_counter()
118 if (cxt->nextpage >= cxt->oops_pages) in mtdoops_inc_counter()
119 cxt->nextpage = 0; in mtdoops_inc_counter()
120 cxt->nextcount++; in mtdoops_inc_counter()
121 if (cxt->nextcount == 0xffffffff) in mtdoops_inc_counter()
122 cxt->nextcount = 0; in mtdoops_inc_counter()
124 if (page_is_used(cxt, cxt->nextpage)) { in mtdoops_inc_counter()
125 schedule_work(&cxt->work_erase); in mtdoops_inc_counter()
130 cxt->nextpage, cxt->nextcount); in mtdoops_inc_counter()
136 struct mtdoops_context *cxt = in mtdoops_workfunc_erase() local
138 struct mtd_info *mtd = cxt->mtd; in mtdoops_workfunc_erase()
145 mod = (cxt->nextpage * record_size) % mtd->erasesize; in mtdoops_workfunc_erase()
147 cxt->nextpage = cxt->nextpage + ((mtd->erasesize - mod) / record_size); in mtdoops_workfunc_erase()
148 if (cxt->nextpage >= cxt->oops_pages) in mtdoops_workfunc_erase()
149 cxt->nextpage = 0; in mtdoops_workfunc_erase()
152 while ((ret = mtd_block_isbad(mtd, cxt->nextpage * record_size)) > 0) { in mtdoops_workfunc_erase()
155 cxt->nextpage * record_size); in mtdoops_workfunc_erase()
157 cxt->nextpage = cxt->nextpage + (mtd->erasesize / record_size); in mtdoops_workfunc_erase()
158 if (cxt->nextpage >= cxt->oops_pages) in mtdoops_workfunc_erase()
159 cxt->nextpage = 0; in mtdoops_workfunc_erase()
160 if (i == cxt->oops_pages / (mtd->erasesize / record_size)) { in mtdoops_workfunc_erase()
172 ret = mtdoops_erase_block(cxt, cxt->nextpage * record_size); in mtdoops_workfunc_erase()
176 cxt->nextpage, cxt->nextcount); in mtdoops_workfunc_erase()
181 ret = mtd_block_markbad(mtd, cxt->nextpage * record_size); in mtdoops_workfunc_erase()
190 static void mtdoops_write(struct mtdoops_context *cxt, int panic) in mtdoops_write() argument
192 struct mtd_info *mtd = cxt->mtd; in mtdoops_write()
198 hdr = cxt->oops_buf; in mtdoops_write()
199 hdr[0] = cxt->nextcount; in mtdoops_write()
203 ret = mtd_panic_write(mtd, cxt->nextpage * record_size, in mtdoops_write()
204 record_size, &retlen, cxt->oops_buf); in mtdoops_write()
210 ret = mtd_write(mtd, cxt->nextpage * record_size, in mtdoops_write()
211 record_size, &retlen, cxt->oops_buf); in mtdoops_write()
215 cxt->nextpage * record_size, retlen, record_size, ret); in mtdoops_write()
216 mark_page_used(cxt, cxt->nextpage); in mtdoops_write()
217 memset(cxt->oops_buf, 0xff, record_size); in mtdoops_write()
219 mtdoops_inc_counter(cxt); in mtdoops_write()
224 struct mtdoops_context *cxt = in mtdoops_workfunc_write() local
227 mtdoops_write(cxt, 0); in mtdoops_workfunc_write()
230 static void find_next_position(struct mtdoops_context *cxt) in find_next_position() argument
232 struct mtd_info *mtd = cxt->mtd; in find_next_position()
237 for (page = 0; page < cxt->oops_pages; page++) { in find_next_position()
241 mark_page_used(cxt, page); in find_next_position()
253 mark_page_unused(cxt, page); in find_next_position()
272 cxt->nextpage = cxt->oops_pages - 1; in find_next_position()
273 cxt->nextcount = 0; in find_next_position()
276 cxt->nextpage = maxpos; in find_next_position()
277 cxt->nextcount = maxcount; in find_next_position()
280 mtdoops_inc_counter(cxt); in find_next_position()
286 struct mtdoops_context *cxt = container_of(dumper, in mtdoops_do_dump() local
293 kmsg_dump_get_buffer(dumper, true, cxt->oops_buf + MTDOOPS_HEADER_SIZE, in mtdoops_do_dump()
298 mtdoops_write(cxt, 1); in mtdoops_do_dump()
301 schedule_work(&cxt->work_write); in mtdoops_do_dump()
306 struct mtdoops_context *cxt = &oops_cxt; in mtdoops_notify_add() local
311 cxt->mtd_index = mtd->index; in mtdoops_notify_add()
313 if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0) in mtdoops_notify_add()
333 cxt->oops_page_used = in mtdoops_notify_add()
337 if (!cxt->oops_page_used) { in mtdoops_notify_add()
342 cxt->dump.max_reason = KMSG_DUMP_OOPS; in mtdoops_notify_add()
343 cxt->dump.dump = mtdoops_do_dump; in mtdoops_notify_add()
344 err = kmsg_dump_register(&cxt->dump); in mtdoops_notify_add()
347 vfree(cxt->oops_page_used); in mtdoops_notify_add()
348 cxt->oops_page_used = NULL; in mtdoops_notify_add()
352 cxt->mtd = mtd; in mtdoops_notify_add()
353 cxt->oops_pages = (int)mtd->size / record_size; in mtdoops_notify_add()
354 find_next_position(cxt); in mtdoops_notify_add()
360 struct mtdoops_context *cxt = &oops_cxt; in mtdoops_notify_remove() local
362 if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0) in mtdoops_notify_remove()
365 if (kmsg_dump_unregister(&cxt->dump) < 0) in mtdoops_notify_remove()
368 cxt->mtd = NULL; in mtdoops_notify_remove()
369 flush_work(&cxt->work_erase); in mtdoops_notify_remove()
370 flush_work(&cxt->work_write); in mtdoops_notify_remove()
381 struct mtdoops_context *cxt = &oops_cxt; in mtdoops_init() local
399 cxt->mtd_index = -1; in mtdoops_init()
402 cxt->mtd_index = mtd_index; in mtdoops_init()
404 cxt->oops_buf = vmalloc(record_size); in mtdoops_init()
405 if (!cxt->oops_buf) { in mtdoops_init()
409 memset(cxt->oops_buf, 0xff, record_size); in mtdoops_init()
411 INIT_WORK(&cxt->work_erase, mtdoops_workfunc_erase); in mtdoops_init()
412 INIT_WORK(&cxt->work_write, mtdoops_workfunc_write); in mtdoops_init()
420 struct mtdoops_context *cxt = &oops_cxt; in mtdoops_exit() local
423 vfree(cxt->oops_buf); in mtdoops_exit()
424 vfree(cxt->oops_page_used); in mtdoops_exit()