Lines Matching refs:cxt
317 struct psz_context *cxt = &pstore_zone_cxt;
320 if (cxt->ppsz)
321 ret |= psz_flush_dirty_zone(cxt->ppsz);
322 if (cxt->cpsz)
323 ret |= psz_flush_dirty_zone(cxt->cpsz);
324 if (cxt->kpszs)
325 ret |= psz_flush_dirty_zones(cxt->kpszs, cxt->kmsg_max_cnt);
326 if (cxt->fpszs)
327 ret |= psz_flush_dirty_zones(cxt->fpszs, cxt->ftrace_max_cnt);
328 if (ret && cxt->pstore_zone_info)
332 static int psz_kmsg_recover_data(struct psz_context *cxt)
334 struct pstore_zone_info *info = cxt->pstore_zone_info;
343 for (i = 0; i < cxt->kmsg_max_cnt; i++) {
344 zone = cxt->kpszs[i];
348 unsigned int wcnt = cxt->kmsg_write_cnt;
349 struct pstore_zone *new = cxt->kpszs[wcnt];
358 cxt->kmsg_write_cnt = (wcnt + 1) % cxt->kmsg_max_cnt;
371 static int psz_kmsg_recover_meta(struct psz_context *cxt)
373 struct pstore_zone_info *info = cxt->pstore_zone_info;
391 for (i = 0; i < cxt->kmsg_max_cnt; i++) {
392 zone = cxt->kpszs[i];
432 cxt->kmsg_write_cnt = (i + 1) % cxt->kmsg_max_cnt;
436 cxt->oops_counter =
437 max(cxt->oops_counter, hdr->counter);
439 cxt->panic_counter =
440 max(cxt->panic_counter, hdr->counter);
460 static int psz_kmsg_recover(struct psz_context *cxt)
464 if (!cxt->kpszs)
467 ret = psz_kmsg_recover_meta(cxt);
471 ret = psz_kmsg_recover_data(cxt);
481 static int psz_recover_zone(struct psz_context *cxt, struct pstore_zone *zone)
483 struct pstore_zone_info *info = cxt->pstore_zone_info;
568 static int psz_recover_zones(struct psz_context *cxt,
582 ret = psz_recover_zone(cxt, zone);
595 * @cxt: the context of pstore/zone
601 static inline int psz_recovery(struct psz_context *cxt)
605 if (atomic_read(&cxt->recovered))
608 ret = psz_kmsg_recover(cxt);
612 ret = psz_recover_zone(cxt, cxt->ppsz);
616 ret = psz_recover_zone(cxt, cxt->cpsz);
620 ret = psz_recover_zones(cxt, cxt->fpszs, cxt->ftrace_max_cnt);
627 atomic_set(&cxt->recovered, 1);
634 struct psz_context *cxt = psi->data;
636 cxt->kmsg_read_cnt = 0;
637 cxt->pmsg_read_cnt = 0;
638 cxt->console_read_cnt = 0;
639 cxt->ftrace_read_cnt = 0;
657 static inline int psz_kmsg_erase(struct psz_context *cxt,
674 if (cxt->pstore_zone_info->erase)
675 return cxt->pstore_zone_info->erase(size, zone->off);
680 static inline int psz_record_erase(struct psz_context *cxt,
701 struct psz_context *cxt = record->psi->data;
705 if (record->id >= cxt->kmsg_max_cnt)
707 return psz_kmsg_erase(cxt, cxt->kpszs[record->id], record);
709 return psz_record_erase(cxt, cxt->ppsz);
711 return psz_record_erase(cxt, cxt->cpsz);
713 if (record->id >= cxt->ftrace_max_cnt)
715 return psz_record_erase(cxt, cxt->fpszs[record->id]);
723 struct psz_context *cxt = record->psi->data;
734 hdr->counter = ++cxt->oops_counter;
736 hdr->counter = ++cxt->panic_counter;
743 * start at cxt->kmsg_write_cnt.
745 static inline int notrace psz_kmsg_write_record(struct psz_context *cxt,
752 for (i = 0; i < cxt->kmsg_max_cnt; i++) {
756 zonenum = (cxt->kmsg_write_cnt + i) % cxt->kmsg_max_cnt;
757 zone = cxt->kpszs[zonenum];
777 cxt->kmsg_write_cnt = zonenum + 1;
778 cxt->kmsg_write_cnt %= cxt->kmsg_max_cnt;
795 static int notrace psz_kmsg_write(struct psz_context *cxt,
809 if (!cxt->kpszs)
812 ret = psz_kmsg_write_record(cxt, record);
874 struct psz_context *cxt = record->psi->data;
878 atomic_set(&cxt->on_panic, 1);
889 return psz_kmsg_write(cxt, record);
891 return psz_record_write(cxt->cpsz, record);
893 return psz_record_write(cxt->ppsz, record);
897 if (!cxt->fpszs)
899 return psz_record_write(cxt->fpszs[zonenum], record);
906 static struct pstore_zone *psz_read_next_zone(struct psz_context *cxt)
910 while (cxt->kmsg_read_cnt < cxt->kmsg_max_cnt) {
911 zone = cxt->kpszs[cxt->kmsg_read_cnt++];
916 if (cxt->ftrace_read_cnt < cxt->ftrace_max_cnt)
922 return cxt->fpszs[cxt->ftrace_read_cnt++];
924 if (cxt->pmsg_read_cnt == 0) {
925 cxt->pmsg_read_cnt++;
926 zone = cxt->ppsz;
931 if (cxt->console_read_cnt == 0) {
932 cxt->console_read_cnt++;
933 zone = cxt->cpsz;
1002 struct psz_context *cxt;
1022 cxt = record->psi->data;
1023 if (cxt->ftrace_read_cnt < cxt->ftrace_max_cnt)
1058 struct psz_context *cxt = record->psi->data;
1065 ret = psz_recovery(cxt);
1070 zone = psz_read_next_zone(cxt);
1078 record->id = cxt->kmsg_read_cnt - 1;
1138 static void psz_free_all_zones(struct psz_context *cxt)
1140 if (cxt->kpszs)
1141 psz_free_zones(&cxt->kpszs, &cxt->kmsg_max_cnt);
1142 if (cxt->ppsz)
1143 psz_free_zone(&cxt->ppsz);
1144 if (cxt->cpsz)
1145 psz_free_zone(&cxt->cpsz);
1146 if (cxt->fpszs)
1147 psz_free_zones(&cxt->fpszs, &cxt->ftrace_max_cnt);
1234 static int psz_alloc_zones(struct psz_context *cxt)
1236 struct pstore_zone_info *info = cxt->pstore_zone_info;
1242 cxt->ppsz = psz_init_zone(PSTORE_TYPE_PMSG, &off, info->pmsg_size);
1243 if (IS_ERR(cxt->ppsz)) {
1244 err = PTR_ERR(cxt->ppsz);
1245 cxt->ppsz = NULL;
1250 cxt->cpsz = psz_init_zone(PSTORE_TYPE_CONSOLE, &off,
1252 if (IS_ERR(cxt->cpsz)) {
1253 err = PTR_ERR(cxt->cpsz);
1254 cxt->cpsz = NULL;
1259 cxt->fpszs = psz_init_zones(PSTORE_TYPE_FTRACE, &off,
1262 &cxt->ftrace_max_cnt);
1263 if (IS_ERR(cxt->fpszs)) {
1264 err = PTR_ERR(cxt->fpszs);
1265 cxt->fpszs = NULL;
1269 cxt->kpszs = psz_init_zones(PSTORE_TYPE_DMESG, &off,
1271 info->kmsg_size, &cxt->kmsg_max_cnt);
1272 if (IS_ERR(cxt->kpszs)) {
1273 err = PTR_ERR(cxt->kpszs);
1274 cxt->kpszs = NULL;
1280 psz_free_all_zones(cxt);
1296 struct psz_context *cxt = &pstore_zone_cxt;
1346 mutex_lock(&cxt->pstore_zone_info_lock);
1347 if (cxt->pstore_zone_info) {
1349 cxt->pstore_zone_info->name, info->name);
1350 mutex_unlock(&cxt->pstore_zone_info_lock);
1353 cxt->pstore_zone_info = info;
1362 err = psz_alloc_zones(cxt);
1369 cxt->pstore.bufsize = cxt->kpszs[0]->buffer_size -
1371 cxt->pstore.buf = kzalloc(cxt->pstore.bufsize, GFP_KERNEL);
1372 if (!cxt->pstore.buf) {
1377 cxt->pstore.data = cxt;
1380 cxt->pstore.max_reason = info->max_reason;
1381 cxt->pstore.name = info->name;
1383 cxt->pstore.flags |= PSTORE_FLAGS_DMESG;
1385 kmsg_dump_reason_str(cxt->pstore.max_reason));
1386 if (cxt->pstore_zone_info->panic_write)
1391 cxt->pstore.flags |= PSTORE_FLAGS_PMSG;
1395 cxt->pstore.flags |= PSTORE_FLAGS_CONSOLE;
1399 cxt->pstore.flags |= PSTORE_FLAGS_FTRACE;
1404 err = pstore_register(&cxt->pstore);
1414 kfree(cxt->pstore.buf);
1415 cxt->pstore.buf = NULL;
1416 cxt->pstore.bufsize = 0;
1417 psz_free_all_zones(cxt);
1432 struct psz_context *cxt = &pstore_zone_cxt;
1434 mutex_lock(&cxt->pstore_zone_info_lock);
1435 if (!cxt->pstore_zone_info) {
1436 mutex_unlock(&cxt->pstore_zone_info_lock);
1441 pstore_unregister(&cxt->pstore);
1448 kfree(cxt->pstore.buf);
1449 cxt->pstore.buf = NULL;
1450 cxt->pstore.bufsize = 0;
1451 cxt->pstore_zone_info = NULL;
1453 psz_free_all_zones(cxt);
1456 cxt->oops_counter = 0;
1457 cxt->panic_counter = 0;
1458 atomic_set(&cxt->recovered, 0);
1459 atomic_set(&cxt->on_panic, 0);
1461 mutex_unlock(&cxt->pstore_zone_info_lock);