Lines Matching refs:cxt
66 static void mark_page_used(struct mtdoops_context *cxt, int page) in mark_page_used() argument
68 set_bit(page, cxt->oops_page_used); in mark_page_used()
71 static void mark_page_unused(struct mtdoops_context *cxt, int page) in mark_page_unused() argument
73 clear_bit(page, cxt->oops_page_used); in mark_page_unused()
76 static int page_is_used(struct mtdoops_context *cxt, int page) in page_is_used() argument
78 return test_bit(page, cxt->oops_page_used); in page_is_used()
81 static int mtdoops_erase_block(struct mtdoops_context *cxt, int offset) in mtdoops_erase_block() argument
83 struct mtd_info *mtd = cxt->mtd; in mtdoops_erase_block()
104 mark_page_unused(cxt, page); in mtdoops_erase_block()
109 static void mtdoops_inc_counter(struct mtdoops_context *cxt) in mtdoops_inc_counter() argument
111 cxt->nextpage++; in mtdoops_inc_counter()
112 if (cxt->nextpage >= cxt->oops_pages) in mtdoops_inc_counter()
113 cxt->nextpage = 0; in mtdoops_inc_counter()
114 cxt->nextcount++; in mtdoops_inc_counter()
115 if (cxt->nextcount == 0xffffffff) in mtdoops_inc_counter()
116 cxt->nextcount = 0; in mtdoops_inc_counter()
118 if (page_is_used(cxt, cxt->nextpage)) { in mtdoops_inc_counter()
119 schedule_work(&cxt->work_erase); in mtdoops_inc_counter()
124 cxt->nextpage, cxt->nextcount); in mtdoops_inc_counter()
130 struct mtdoops_context *cxt = in mtdoops_workfunc_erase() local
132 struct mtd_info *mtd = cxt->mtd; in mtdoops_workfunc_erase()
139 mod = (cxt->nextpage * record_size) % mtd->erasesize; in mtdoops_workfunc_erase()
141 cxt->nextpage = cxt->nextpage + ((mtd->erasesize - mod) / record_size); in mtdoops_workfunc_erase()
142 if (cxt->nextpage >= cxt->oops_pages) in mtdoops_workfunc_erase()
143 cxt->nextpage = 0; in mtdoops_workfunc_erase()
146 while ((ret = mtd_block_isbad(mtd, cxt->nextpage * record_size)) > 0) { in mtdoops_workfunc_erase()
149 cxt->nextpage * record_size); in mtdoops_workfunc_erase()
151 cxt->nextpage = cxt->nextpage + (mtd->erasesize / record_size); in mtdoops_workfunc_erase()
152 if (cxt->nextpage >= cxt->oops_pages) in mtdoops_workfunc_erase()
153 cxt->nextpage = 0; in mtdoops_workfunc_erase()
154 if (i == cxt->oops_pages / (mtd->erasesize / record_size)) { in mtdoops_workfunc_erase()
166 ret = mtdoops_erase_block(cxt, cxt->nextpage * record_size); in mtdoops_workfunc_erase()
170 cxt->nextpage, cxt->nextcount); in mtdoops_workfunc_erase()
175 ret = mtd_block_markbad(mtd, cxt->nextpage * record_size); in mtdoops_workfunc_erase()
184 static void mtdoops_write(struct mtdoops_context *cxt, int panic) in mtdoops_write() argument
186 struct mtd_info *mtd = cxt->mtd; in mtdoops_write()
191 if (test_and_set_bit(0, &cxt->oops_buf_busy)) in mtdoops_write()
195 hdr = (struct mtdoops_hdr *)cxt->oops_buf; in mtdoops_write()
196 hdr->seq = cxt->nextcount; in mtdoops_write()
201 ret = mtd_panic_write(mtd, cxt->nextpage * record_size, in mtdoops_write()
202 record_size, &retlen, cxt->oops_buf); in mtdoops_write()
208 ret = mtd_write(mtd, cxt->nextpage * record_size, in mtdoops_write()
209 record_size, &retlen, cxt->oops_buf); in mtdoops_write()
213 cxt->nextpage * record_size, retlen, record_size, ret); in mtdoops_write()
214 mark_page_used(cxt, cxt->nextpage); in mtdoops_write()
215 memset(cxt->oops_buf, 0xff, record_size); in mtdoops_write()
217 mtdoops_inc_counter(cxt); in mtdoops_write()
219 clear_bit(0, &cxt->oops_buf_busy); 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()
238 for (page = 0; page < cxt->oops_pages; page++) { in find_next_position()
242 mark_page_used(cxt, page); in find_next_position()
253 mark_page_unused(cxt, page); in find_next_position()
274 cxt->nextpage = cxt->oops_pages - 1; in find_next_position()
275 cxt->nextcount = 0; in find_next_position()
278 cxt->nextpage = maxpos; in find_next_position()
279 cxt->nextcount = maxcount; in find_next_position()
282 mtdoops_inc_counter(cxt); in find_next_position()
288 struct mtdoops_context *cxt = container_of(dumper, in mtdoops_do_dump() local
298 if (test_and_set_bit(0, &cxt->oops_buf_busy)) in mtdoops_do_dump()
301 cxt->oops_buf + sizeof(struct mtdoops_hdr), in mtdoops_do_dump()
303 clear_bit(0, &cxt->oops_buf_busy); in mtdoops_do_dump()
307 mtdoops_write(cxt, 1); in mtdoops_do_dump()
310 schedule_work(&cxt->work_write); in mtdoops_do_dump()
316 struct mtdoops_context *cxt = &oops_cxt; in mtdoops_notify_add() local
321 cxt->mtd_index = mtd->index; in mtdoops_notify_add()
323 if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0) in mtdoops_notify_add()
343 cxt->oops_page_used = in mtdoops_notify_add()
347 if (!cxt->oops_page_used) { in mtdoops_notify_add()
352 cxt->dump.max_reason = KMSG_DUMP_OOPS; in mtdoops_notify_add()
353 cxt->dump.dump = mtdoops_do_dump; in mtdoops_notify_add()
354 err = kmsg_dump_register(&cxt->dump); in mtdoops_notify_add()
357 vfree(cxt->oops_page_used); in mtdoops_notify_add()
358 cxt->oops_page_used = NULL; in mtdoops_notify_add()
362 cxt->mtd = mtd; in mtdoops_notify_add()
363 cxt->oops_pages = (int)mtd->size / record_size; in mtdoops_notify_add()
364 find_next_position(cxt); in mtdoops_notify_add()
370 struct mtdoops_context *cxt = &oops_cxt; in mtdoops_notify_remove() local
372 if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0) in mtdoops_notify_remove()
375 if (kmsg_dump_unregister(&cxt->dump) < 0) in mtdoops_notify_remove()
378 cxt->mtd = NULL; in mtdoops_notify_remove()
379 flush_work(&cxt->work_erase); in mtdoops_notify_remove()
380 flush_work(&cxt->work_write); in mtdoops_notify_remove()
391 struct mtdoops_context *cxt = &oops_cxt; in mtdoops_init() local
409 cxt->mtd_index = -1; in mtdoops_init()
412 cxt->mtd_index = mtd_index; in mtdoops_init()
414 cxt->oops_buf = vmalloc(record_size); in mtdoops_init()
415 if (!cxt->oops_buf) in mtdoops_init()
417 memset(cxt->oops_buf, 0xff, record_size); in mtdoops_init()
418 cxt->oops_buf_busy = 0; in mtdoops_init()
420 INIT_WORK(&cxt->work_erase, mtdoops_workfunc_erase); in mtdoops_init()
421 INIT_WORK(&cxt->work_write, mtdoops_workfunc_write); in mtdoops_init()
429 struct mtdoops_context *cxt = &oops_cxt; in mtdoops_exit() local
432 vfree(cxt->oops_buf); in mtdoops_exit()
433 vfree(cxt->oops_page_used); in mtdoops_exit()