1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright (c) Meta Platforms, Inc. and affiliates. */ 3 4 #ifndef _FBNIC_FW_LOG_H_ 5 #define _FBNIC_FW_LOG_H_ 6 7 #include <linux/spinlock.h> 8 #include <linux/types.h> 9 10 /* A 512K log buffer was chosen fairly arbitrarily */ 11 #define FBNIC_FW_LOG_SIZE (512 * 1024) /* bytes */ 12 13 /* Firmware log output is prepended with log index followed by a timestamp. 14 * The timestamp is similar to Zephyr's format DD:HH:MM:SS.MMM 15 */ 16 #define FBNIC_FW_LOG_FMT "[%5lld] [%02ld:%02ld:%02ld:%02ld.%03ld] %s\n" 17 18 struct fbnic_dev; 19 20 struct fbnic_fw_log_entry { 21 struct list_head list; 22 u64 index; 23 u32 timestamp; 24 u16 len; 25 char msg[] __counted_by(len); 26 }; 27 28 struct fbnic_fw_log { 29 void *data_start; 30 void *data_end; 31 size_t size; 32 struct list_head entries; 33 /* Spin lock for accessing or modifying entries */ 34 spinlock_t lock; 35 }; 36 37 #define fbnic_fw_log_ready(_fbd) (!!(_fbd)->fw_log.data_start) 38 39 void fbnic_fw_log_enable(struct fbnic_dev *fbd, bool send_hist); 40 void fbnic_fw_log_disable(struct fbnic_dev *fbd); 41 int fbnic_fw_log_init(struct fbnic_dev *fbd); 42 void fbnic_fw_log_free(struct fbnic_dev *fbd); 43 int fbnic_fw_log_write(struct fbnic_dev *fbd, u64 index, u32 timestamp, 44 char *msg); 45 #endif /* _FBNIC_FW_LOG_H_ */ 46