Lines Matching refs:cxt

59 static void mark_page_used(struct mtdoops_context *cxt, int page)  in mark_page_used()  argument
61 set_bit(page, cxt->oops_page_used); in mark_page_used()
64 static void mark_page_unused(struct mtdoops_context *cxt, int page) in mark_page_unused() argument
66 clear_bit(page, cxt->oops_page_used); in mark_page_unused()
69 static int page_is_used(struct mtdoops_context *cxt, int page) in page_is_used() argument
71 return test_bit(page, cxt->oops_page_used); in page_is_used()
74 static int mtdoops_erase_block(struct mtdoops_context *cxt, int offset) in mtdoops_erase_block() argument
76 struct mtd_info *mtd = cxt->mtd; in mtdoops_erase_block()
97 mark_page_unused(cxt, page); in mtdoops_erase_block()
102 static void mtdoops_inc_counter(struct mtdoops_context *cxt) in mtdoops_inc_counter() argument
104 cxt->nextpage++; in mtdoops_inc_counter()
105 if (cxt->nextpage >= cxt->oops_pages) in mtdoops_inc_counter()
106 cxt->nextpage = 0; in mtdoops_inc_counter()
107 cxt->nextcount++; in mtdoops_inc_counter()
108 if (cxt->nextcount == 0xffffffff) in mtdoops_inc_counter()
109 cxt->nextcount = 0; in mtdoops_inc_counter()
111 if (page_is_used(cxt, cxt->nextpage)) { in mtdoops_inc_counter()
112 schedule_work(&cxt->work_erase); in mtdoops_inc_counter()
117 cxt->nextpage, cxt->nextcount); in mtdoops_inc_counter()
123 struct mtdoops_context *cxt = in mtdoops_workfunc_erase() local
125 struct mtd_info *mtd = cxt->mtd; in mtdoops_workfunc_erase()
132 mod = (cxt->nextpage * record_size) % mtd->erasesize; in mtdoops_workfunc_erase()
134 cxt->nextpage = cxt->nextpage + ((mtd->erasesize - mod) / record_size); in mtdoops_workfunc_erase()
135 if (cxt->nextpage >= cxt->oops_pages) in mtdoops_workfunc_erase()
136 cxt->nextpage = 0; in mtdoops_workfunc_erase()
139 while ((ret = mtd_block_isbad(mtd, cxt->nextpage * record_size)) > 0) { in mtdoops_workfunc_erase()
142 cxt->nextpage * record_size); in mtdoops_workfunc_erase()
144 cxt->nextpage = cxt->nextpage + (mtd->erasesize / record_size); in mtdoops_workfunc_erase()
145 if (cxt->nextpage >= cxt->oops_pages) in mtdoops_workfunc_erase()
146 cxt->nextpage = 0; in mtdoops_workfunc_erase()
147 if (i == cxt->oops_pages / (mtd->erasesize / record_size)) { in mtdoops_workfunc_erase()
159 ret = mtdoops_erase_block(cxt, cxt->nextpage * record_size); in mtdoops_workfunc_erase()
163 cxt->nextpage, cxt->nextcount); in mtdoops_workfunc_erase()
168 ret = mtd_block_markbad(mtd, cxt->nextpage * record_size); in mtdoops_workfunc_erase()
177 static void mtdoops_write(struct mtdoops_context *cxt, int panic) in mtdoops_write() argument
179 struct mtd_info *mtd = cxt->mtd; in mtdoops_write()
184 if (test_and_set_bit(0, &cxt->oops_buf_busy)) in mtdoops_write()
188 hdr = cxt->oops_buf; in mtdoops_write()
189 hdr[0] = cxt->nextcount; in mtdoops_write()
193 ret = mtd_panic_write(mtd, cxt->nextpage * record_size, in mtdoops_write()
194 record_size, &retlen, cxt->oops_buf); in mtdoops_write()
200 ret = mtd_write(mtd, cxt->nextpage * record_size, in mtdoops_write()
201 record_size, &retlen, cxt->oops_buf); in mtdoops_write()
205 cxt->nextpage * record_size, retlen, record_size, ret); in mtdoops_write()
206 mark_page_used(cxt, cxt->nextpage); in mtdoops_write()
207 memset(cxt->oops_buf, 0xff, record_size); in mtdoops_write()
209 mtdoops_inc_counter(cxt); in mtdoops_write()
211 clear_bit(0, &cxt->oops_buf_busy); in mtdoops_write()
216 struct mtdoops_context *cxt = in mtdoops_workfunc_write() local
219 mtdoops_write(cxt, 0); in mtdoops_workfunc_write()
222 static void find_next_position(struct mtdoops_context *cxt) in find_next_position() argument
224 struct mtd_info *mtd = cxt->mtd; in find_next_position()
229 for (page = 0; page < cxt->oops_pages; page++) { in find_next_position()
233 mark_page_used(cxt, page); in find_next_position()
245 mark_page_unused(cxt, page); in find_next_position()
264 cxt->nextpage = cxt->oops_pages - 1; in find_next_position()
265 cxt->nextcount = 0; in find_next_position()
268 cxt->nextpage = maxpos; in find_next_position()
269 cxt->nextcount = maxcount; in find_next_position()
272 mtdoops_inc_counter(cxt); in find_next_position()
278 struct mtdoops_context *cxt = container_of(dumper, in mtdoops_do_dump() local
288 if (test_and_set_bit(0, &cxt->oops_buf_busy)) in mtdoops_do_dump()
290 kmsg_dump_get_buffer(&iter, true, cxt->oops_buf + MTDOOPS_HEADER_SIZE, in mtdoops_do_dump()
292 clear_bit(0, &cxt->oops_buf_busy); in mtdoops_do_dump()
296 mtdoops_write(cxt, 1); in mtdoops_do_dump()
299 schedule_work(&cxt->work_write); in mtdoops_do_dump()
305 struct mtdoops_context *cxt = &oops_cxt; in mtdoops_notify_add() local
310 cxt->mtd_index = mtd->index; in mtdoops_notify_add()
312 if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0) in mtdoops_notify_add()
332 cxt->oops_page_used = in mtdoops_notify_add()
336 if (!cxt->oops_page_used) { in mtdoops_notify_add()
341 cxt->dump.max_reason = KMSG_DUMP_OOPS; in mtdoops_notify_add()
342 cxt->dump.dump = mtdoops_do_dump; in mtdoops_notify_add()
343 err = kmsg_dump_register(&cxt->dump); in mtdoops_notify_add()
346 vfree(cxt->oops_page_used); in mtdoops_notify_add()
347 cxt->oops_page_used = NULL; in mtdoops_notify_add()
351 cxt->mtd = mtd; in mtdoops_notify_add()
352 cxt->oops_pages = (int)mtd->size / record_size; in mtdoops_notify_add()
353 find_next_position(cxt); in mtdoops_notify_add()
359 struct mtdoops_context *cxt = &oops_cxt; in mtdoops_notify_remove() local
361 if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0) in mtdoops_notify_remove()
364 if (kmsg_dump_unregister(&cxt->dump) < 0) in mtdoops_notify_remove()
367 cxt->mtd = NULL; in mtdoops_notify_remove()
368 flush_work(&cxt->work_erase); in mtdoops_notify_remove()
369 flush_work(&cxt->work_write); in mtdoops_notify_remove()
380 struct mtdoops_context *cxt = &oops_cxt; in mtdoops_init() local
398 cxt->mtd_index = -1; in mtdoops_init()
401 cxt->mtd_index = mtd_index; in mtdoops_init()
403 cxt->oops_buf = vmalloc(record_size); in mtdoops_init()
404 if (!cxt->oops_buf) in mtdoops_init()
406 memset(cxt->oops_buf, 0xff, record_size); in mtdoops_init()
407 cxt->oops_buf_busy = 0; in mtdoops_init()
409 INIT_WORK(&cxt->work_erase, mtdoops_workfunc_erase); in mtdoops_init()
410 INIT_WORK(&cxt->work_write, mtdoops_workfunc_write); in mtdoops_init()
418 struct mtdoops_context *cxt = &oops_cxt; in mtdoops_exit() local
421 vfree(cxt->oops_buf); in mtdoops_exit()
422 vfree(cxt->oops_page_used); in mtdoops_exit()