• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2021 Huawei Technologies Co., Ltd. All rights reserved.
4  */
5 
6 #ifndef BLACKBOX_H
7 #define BLACKBOX_H
8 
9 #include <linux/printk.h>
10 #include <linux/time.h>
11 
12 #define PATH_MAX_LEN         256
13 #define EVENT_MAX_LEN        32
14 #define CATEGORY_MAX_LEN     32
15 #define MODULE_MAX_LEN       32
16 #define TIMESTAMP_MAX_LEN    24
17 #define ERROR_DESC_MAX_LEN   512
18 #define LOG_FLAG             "VALIDLOG"
19 
20 /* module type */
21 #define MODULE_SYSTEM        "SYSTEM"
22 
23 /* fault category type */
24 #define CATEGORY_SYSTEM_REBOOT         "SYSREBOOT"
25 #define CATEGORY_SYSTEM_POWEROFF       "POWEROFF"
26 #define CATEGORY_SYSTEM_PANIC          "PANIC"
27 #define CATEGORY_SYSTEM_OOPS           "OOPS"
28 #define CATEGORY_SYSTEM_CUSTOM         "CUSTOM"
29 #define CATEGORY_SYSTEM_WATCHDOG       "HWWATCHDOG"
30 #define CATEGORY_SYSTEM_HUNGTASK       "HUNGTASK"
31 #define CATEGORY_SUBSYSTEM_CUSTOM      "CUSTOM"
32 
33 /* fault event type */
34 #define EVENT_SYSREBOOT      "SYSREBOOT"
35 #define EVENT_LONGPRESS      "LONGPRESS"
36 #define EVENT_COMBINATIONKEY "COMBINATIONKEY"
37 #define EVENT_SUBSYSREBOOT   "SUBSYSREBOOT"
38 #define EVENT_POWEROFF       "POWEROFF"
39 #define EVENT_PANIC          "PANIC"
40 #define EVENT_OOPS           "OOPS"
41 #define EVENT_SYS_WATCHDOG   "SYSWATCHDOG"
42 #define EVENT_HUNGTASK       "HUNGTASK"
43 #define EVENT_BOOTFAIL       "BOOTFAIL"
44 
45 #define FILE_NAME(x) (strrchr(x, '/') ? (strrchr(x, '/') + 1) : x)
46 #define BBOX_DECORATOR_HILOG(level, fmt, args...)  \
47 	pr_err("bbox:[%s][%s:%d] " fmt, level, FILE_NAME(__FILE__), __LINE__, ##args)
48 
49 #define bbox_print_fatal(fmt, args...) BBOX_DECORATOR_HILOG("fatal", fmt, ##args)
50 #define bbox_print_err(fmt, args...) BBOX_DECORATOR_HILOG("err", fmt, ##args)
51 #define bbox_print_warn(fmt, args...) BBOX_DECORATOR_HILOG("warn", fmt, ##args)
52 #define bbox_print_info(fmt, args...) BBOX_DECORATOR_HILOG("info", fmt, ##args)
53 #define bbox_print_debug(fmt, args...) BBOX_DECORATOR_HILOG("debug", fmt, ##args)
54 
55 struct error_info {
56 	char event[EVENT_MAX_LEN];
57 	char category[CATEGORY_MAX_LEN];
58 	char module[MODULE_MAX_LEN];
59 	char error_time[TIMESTAMP_MAX_LEN];
60 	char error_desc[ERROR_DESC_MAX_LEN];
61 };
62 
63 struct fault_log_info {
64 	char flag[8]; /* 8 is the length of the flag */
65 	size_t len; /* length of the kernel fault log */
66 	struct error_info info;
67 };
68 
69 struct module_ops {
70 	char module[MODULE_MAX_LEN];
71 	void (*dump)(const char *log_dir, struct error_info *info);
72 	void (*reset)(struct error_info *info);
73 	int (*get_last_log_info)(struct error_info *info);
74 	int (*save_last_log)(const char *log_dir, struct error_info *info);
75 };
76 
77 void get_timestamp(char *buf, size_t buf_size);
78 int bbox_register_module_ops(struct module_ops *ops);
79 int bbox_notify_error(const char event[EVENT_MAX_LEN],
80 		const char module[MODULE_MAX_LEN],
81 		const char error_desc[ERROR_DESC_MAX_LEN],
82 		int need_sys_reset);
83 
84 #endif /* BLACKBOX_H */
85