| 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* Copyright (C) 2022, Intel Corporation. */ |
| 3 | |
| 4 | #ifndef _LIBIE_FWLOG_H_ |
| 5 | #define _LIBIE_FWLOG_H_ |
| 6 | |
| 7 | #include <linux/net/intel/libie/adminq.h> |
| 8 | |
| 9 | /* Only a single log level should be set and all log levels under the set value |
| 10 | * are enabled, e.g. if log level is set to LIBIE_FW_LOG_LEVEL_VERBOSE, then all |
| 11 | * other log levels are included (except LIBIE_FW_LOG_LEVEL_NONE) |
| 12 | */ |
| 13 | enum libie_fwlog_level { |
| 14 | LIBIE_FWLOG_LEVEL_NONE = 0, |
| 15 | LIBIE_FWLOG_LEVEL_ERROR = 1, |
| 16 | LIBIE_FWLOG_LEVEL_WARNING = 2, |
| 17 | LIBIE_FWLOG_LEVEL_NORMAL = 3, |
| 18 | LIBIE_FWLOG_LEVEL_VERBOSE = 4, |
| 19 | LIBIE_FWLOG_LEVEL_INVALID, /* all values >= this entry are invalid */ |
| 20 | }; |
| 21 | |
| 22 | struct libie_fwlog_module_entry { |
| 23 | /* module ID for the corresponding firmware logging event */ |
| 24 | u16 module_id; |
| 25 | /* verbosity level for the module_id */ |
| 26 | u8 log_level; |
| 27 | }; |
| 28 | |
| 29 | struct libie_fwlog_cfg { |
| 30 | /* list of modules for configuring log level */ |
| 31 | struct libie_fwlog_module_entry module_entries[LIBIE_AQC_FW_LOG_ID_MAX]; |
| 32 | /* options used to configure firmware logging */ |
| 33 | u16 options; |
| 34 | #define LIBIE_FWLOG_OPTION_ARQ_ENA BIT(0) |
| 35 | #define LIBIE_FWLOG_OPTION_UART_ENA BIT(1) |
| 36 | /* set before calling libie_fwlog_init() so the PF registers for |
| 37 | * firmware logging on initialization |
| 38 | */ |
| 39 | #define LIBIE_FWLOG_OPTION_REGISTER_ON_INIT BIT(2) |
| 40 | /* set in the libie_aq_fwlog_get() response if the PF is registered for |
| 41 | * FW logging events over ARQ |
| 42 | */ |
| 43 | #define LIBIE_FWLOG_OPTION_IS_REGISTERED BIT(3) |
| 44 | |
| 45 | /* minimum number of log events sent per Admin Receive Queue event */ |
| 46 | u16 log_resolution; |
| 47 | }; |
| 48 | |
| 49 | struct libie_fwlog_data { |
| 50 | u16 data_size; |
| 51 | u8 *data; |
| 52 | }; |
| 53 | |
| 54 | struct libie_fwlog_ring { |
| 55 | struct libie_fwlog_data *rings; |
| 56 | u16 index; |
| 57 | u16 size; |
| 58 | u16 head; |
| 59 | u16 tail; |
| 60 | }; |
| 61 | |
| 62 | #define LIBIE_FWLOG_RING_SIZE_INDEX_DFLT 3 |
| 63 | #define LIBIE_FWLOG_RING_SIZE_DFLT 256 |
| 64 | #define LIBIE_FWLOG_RING_SIZE_MAX 512 |
| 65 | |
| 66 | struct libie_fwlog { |
| 67 | struct libie_fwlog_cfg cfg; |
| 68 | bool supported; /* does hardware support FW logging? */ |
| 69 | struct libie_fwlog_ring ring; |
| 70 | struct dentry *debugfs; |
| 71 | /* keep track of all the dentrys for FW log modules */ |
| 72 | struct dentry **debugfs_modules; |
| 73 | struct_group_tagged(libie_fwlog_api, api, |
| 74 | struct pci_dev *pdev; |
| 75 | int (*send_cmd)(void *, struct libie_aq_desc *, void *, u16); |
| 76 | void *priv; |
| 77 | struct dentry *debugfs_root; |
| 78 | ); |
| 79 | }; |
| 80 | |
| 81 | #if IS_ENABLED(CONFIG_LIBIE_FWLOG) |
| 82 | int libie_fwlog_init(struct libie_fwlog *fwlog, struct libie_fwlog_api *api); |
| 83 | void libie_fwlog_deinit(struct libie_fwlog *fwlog); |
| 84 | void libie_fwlog_reregister(struct libie_fwlog *fwlog); |
| 85 | void libie_get_fwlog_data(struct libie_fwlog *fwlog, u8 *buf, u16 len); |
| 86 | #else |
| 87 | static inline int libie_fwlog_init(struct libie_fwlog *fwlog, |
| 88 | struct libie_fwlog_api *api) |
| 89 | { |
| 90 | return -EOPNOTSUPP; |
| 91 | } |
| 92 | static inline void libie_fwlog_deinit(struct libie_fwlog *fwlog) { } |
| 93 | static inline void libie_fwlog_reregister(struct libie_fwlog *fwlog) { } |
| 94 | static inline void libie_get_fwlog_data(struct libie_fwlog *fwlog, u8 *buf, |
| 95 | u16 len) { } |
| 96 | #endif /* CONFIG_LIBIE_FWLOG */ |
| 97 | #endif /* _LIBIE_FWLOG_H_ */ |
| 98 | |