Lines Matching refs:cxt

58 static void mark_page_used(struct mtdoops_context *cxt, int page)  in mark_page_used()  argument
60 set_bit(page, cxt->oops_page_used); in mark_page_used()
63 static void mark_page_unused(struct mtdoops_context *cxt, int page) in mark_page_unused() argument
65 clear_bit(page, cxt->oops_page_used); in mark_page_unused()
68 static int page_is_used(struct mtdoops_context *cxt, int page) in page_is_used() argument
70 return test_bit(page, cxt->oops_page_used); in page_is_used()
73 static int mtdoops_erase_block(struct mtdoops_context *cxt, int offset) in mtdoops_erase_block() argument
75 struct mtd_info *mtd = cxt->mtd; in mtdoops_erase_block()
96 mark_page_unused(cxt, page); in mtdoops_erase_block()
101 static void mtdoops_inc_counter(struct mtdoops_context *cxt) in mtdoops_inc_counter() argument
103 cxt->nextpage++; in mtdoops_inc_counter()
104 if (cxt->nextpage >= cxt->oops_pages) in mtdoops_inc_counter()
105 cxt->nextpage = 0; in mtdoops_inc_counter()
106 cxt->nextcount++; in mtdoops_inc_counter()
107 if (cxt->nextcount == 0xffffffff) in mtdoops_inc_counter()
108 cxt->nextcount = 0; in mtdoops_inc_counter()
110 if (page_is_used(cxt, cxt->nextpage)) { in mtdoops_inc_counter()
111 schedule_work(&cxt->work_erase); in mtdoops_inc_counter()
116 cxt->nextpage, cxt->nextcount); in mtdoops_inc_counter()
122 struct mtdoops_context *cxt = in mtdoops_workfunc_erase() local
124 struct mtd_info *mtd = cxt->mtd; in mtdoops_workfunc_erase()
131 mod = (cxt->nextpage * record_size) % mtd->erasesize; in mtdoops_workfunc_erase()
133 cxt->nextpage = cxt->nextpage + ((mtd->erasesize - mod) / record_size); in mtdoops_workfunc_erase()
134 if (cxt->nextpage >= cxt->oops_pages) in mtdoops_workfunc_erase()
135 cxt->nextpage = 0; in mtdoops_workfunc_erase()
138 while ((ret = mtd_block_isbad(mtd, cxt->nextpage * record_size)) > 0) { in mtdoops_workfunc_erase()
141 cxt->nextpage * record_size); in mtdoops_workfunc_erase()
143 cxt->nextpage = cxt->nextpage + (mtd->erasesize / record_size); in mtdoops_workfunc_erase()
144 if (cxt->nextpage >= cxt->oops_pages) in mtdoops_workfunc_erase()
145 cxt->nextpage = 0; in mtdoops_workfunc_erase()
146 if (i == cxt->oops_pages / (mtd->erasesize / record_size)) { in mtdoops_workfunc_erase()
158 ret = mtdoops_erase_block(cxt, cxt->nextpage * record_size); in mtdoops_workfunc_erase()
162 cxt->nextpage, cxt->nextcount); in mtdoops_workfunc_erase()
167 ret = mtd_block_markbad(mtd, cxt->nextpage * record_size); in mtdoops_workfunc_erase()
176 static void mtdoops_write(struct mtdoops_context *cxt, int panic) in mtdoops_write() argument
178 struct mtd_info *mtd = cxt->mtd; in mtdoops_write()
184 hdr = cxt->oops_buf; in mtdoops_write()
185 hdr[0] = cxt->nextcount; in mtdoops_write()
189 ret = mtd_panic_write(mtd, cxt->nextpage * record_size, in mtdoops_write()
190 record_size, &retlen, cxt->oops_buf); in mtdoops_write()
196 ret = mtd_write(mtd, cxt->nextpage * record_size, in mtdoops_write()
197 record_size, &retlen, cxt->oops_buf); in mtdoops_write()
201 cxt->nextpage * record_size, retlen, record_size, ret); in mtdoops_write()
202 mark_page_used(cxt, cxt->nextpage); in mtdoops_write()
203 memset(cxt->oops_buf, 0xff, record_size); in mtdoops_write()
205 mtdoops_inc_counter(cxt); in mtdoops_write()
210 struct mtdoops_context *cxt = in mtdoops_workfunc_write() local
213 mtdoops_write(cxt, 0); in mtdoops_workfunc_write()
216 static void find_next_position(struct mtdoops_context *cxt) in find_next_position() argument
218 struct mtd_info *mtd = cxt->mtd; in find_next_position()
223 for (page = 0; page < cxt->oops_pages; page++) { in find_next_position()
227 mark_page_used(cxt, page); in find_next_position()
239 mark_page_unused(cxt, page); in find_next_position()
258 cxt->nextpage = cxt->oops_pages - 1; in find_next_position()
259 cxt->nextcount = 0; in find_next_position()
262 cxt->nextpage = maxpos; in find_next_position()
263 cxt->nextcount = maxcount; in find_next_position()
266 mtdoops_inc_counter(cxt); in find_next_position()
272 struct mtdoops_context *cxt = container_of(dumper, in mtdoops_do_dump() local
279 kmsg_dump_get_buffer(dumper, true, cxt->oops_buf + MTDOOPS_HEADER_SIZE, in mtdoops_do_dump()
284 mtdoops_write(cxt, 1); in mtdoops_do_dump()
287 schedule_work(&cxt->work_write); in mtdoops_do_dump()
293 struct mtdoops_context *cxt = &oops_cxt; in mtdoops_notify_add() local
298 cxt->mtd_index = mtd->index; in mtdoops_notify_add()
300 if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0) in mtdoops_notify_add()
320 cxt->oops_page_used = in mtdoops_notify_add()
324 if (!cxt->oops_page_used) { in mtdoops_notify_add()
329 cxt->dump.max_reason = KMSG_DUMP_OOPS; in mtdoops_notify_add()
330 cxt->dump.dump = mtdoops_do_dump; in mtdoops_notify_add()
331 err = kmsg_dump_register(&cxt->dump); in mtdoops_notify_add()
334 vfree(cxt->oops_page_used); in mtdoops_notify_add()
335 cxt->oops_page_used = NULL; in mtdoops_notify_add()
339 cxt->mtd = mtd; in mtdoops_notify_add()
340 cxt->oops_pages = (int)mtd->size / record_size; in mtdoops_notify_add()
341 find_next_position(cxt); in mtdoops_notify_add()
347 struct mtdoops_context *cxt = &oops_cxt; in mtdoops_notify_remove() local
349 if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0) in mtdoops_notify_remove()
352 if (kmsg_dump_unregister(&cxt->dump) < 0) in mtdoops_notify_remove()
355 cxt->mtd = NULL; in mtdoops_notify_remove()
356 flush_work(&cxt->work_erase); in mtdoops_notify_remove()
357 flush_work(&cxt->work_write); in mtdoops_notify_remove()
368 struct mtdoops_context *cxt = &oops_cxt; in mtdoops_init() local
386 cxt->mtd_index = -1; in mtdoops_init()
389 cxt->mtd_index = mtd_index; in mtdoops_init()
391 cxt->oops_buf = vmalloc(record_size); in mtdoops_init()
392 if (!cxt->oops_buf) { in mtdoops_init()
396 memset(cxt->oops_buf, 0xff, record_size); in mtdoops_init()
398 INIT_WORK(&cxt->work_erase, mtdoops_workfunc_erase); in mtdoops_init()
399 INIT_WORK(&cxt->work_write, mtdoops_workfunc_write); in mtdoops_init()
407 struct mtdoops_context *cxt = &oops_cxt; in mtdoops_exit() local
410 vfree(cxt->oops_buf); in mtdoops_exit()
411 vfree(cxt->oops_page_used); in mtdoops_exit()