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 MODULE_MAX_LEN 32 15 #define TIMESTAMP_MAX_LEN 24 16 #define ERROR_DESC_MAX_LEN 512 17 #define LOG_FLAG "VALIDLOG" 18 19 /* module type */ 20 #define MODULE_SYSTEM "SYSTEM" 21 22 /* fault event type */ 23 #define EVENT_SYSREBOOT "SYSREBOOT" 24 #define EVENT_LONGPRESS "LONGPRESS" 25 #define EVENT_COMBINATIONKEY "COMBINATIONKEY" 26 #define EVENT_SUBSYSREBOOT "SUBSYSREBOOT" 27 #define EVENT_POWEROFF "POWEROFF" 28 #define EVENT_PANIC "PANIC" 29 #define EVENT_OOPS "OOPS" 30 #define EVENT_SYS_WATCHDOG "SYSWATCHDOG" 31 #define EVENT_HUNGTASK "HUNGTASK" 32 #define EVENT_BOOTFAIL "BOOTFAIL" 33 34 #define bbox_print_err(format, ...) \ 35 pr_err("bbox: func: %s, line: %d, err: " \ 36 format, __func__, __LINE__, ##__VA_ARGS__) 37 #define bbox_print_info(format, ...) \ 38 pr_err("bbox: info: " format, ##__VA_ARGS__) 39 40 struct error_info { 41 char event[EVENT_MAX_LEN]; 42 char module[MODULE_MAX_LEN]; 43 char error_time[TIMESTAMP_MAX_LEN]; 44 char error_desc[ERROR_DESC_MAX_LEN]; 45 }; 46 47 struct fault_log_info { 48 char flag[8]; /* 8 is the length of the flag */ 49 int len; /* length of the kernel fault log */ 50 struct error_info info; 51 }; 52 53 struct module_ops { 54 char module[MODULE_MAX_LEN]; 55 void (*dump)(const char *log_dir, struct error_info *info); 56 void (*reset)(struct error_info *info); 57 int (*get_last_log_info)(struct error_info *info); 58 int (*save_last_log)(const char *log_dir, struct error_info *info); 59 }; 60 61 void get_timestamp(char *buf, size_t buf_size); 62 int bbox_register_module_ops(struct module_ops *ops); 63 int bbox_notify_error(const char event[EVENT_MAX_LEN], 64 const char module[MODULE_MAX_LEN], 65 const char error_desc[ERROR_DESC_MAX_LEN], 66 int need_sys_reset); 67 68 #endif /* BLACKBOX_H */ 69