Tomas Winkler | ab69a5a | 2009-10-17 09:09:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * iwmc3200top - Intel Wireless MultiCom 3200 Top Driver |
| 3 | * drivers/misc/iwmc3200top/log.h |
| 4 | * |
| 5 | * Copyright (C) 2009 Intel Corporation. All rights reserved. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License version |
| 9 | * 2 as published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 19 | * 02110-1301, USA. |
| 20 | * |
| 21 | * |
| 22 | * Author Name: Maxim Grabarnik <maxim.grabarnink@intel.com> |
| 23 | * - |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #ifndef __LOG_H__ |
| 28 | #define __LOG_H__ |
| 29 | |
| 30 | |
| 31 | /* log severity: |
| 32 | * The log levels here match FW log levels |
| 33 | * so values need to stay as is */ |
| 34 | #define LOG_SEV_CRITICAL 0 |
| 35 | #define LOG_SEV_ERROR 1 |
| 36 | #define LOG_SEV_WARNING 2 |
| 37 | #define LOG_SEV_INFO 3 |
| 38 | #define LOG_SEV_INFOEX 4 |
| 39 | |
Tomas Winkler | 0df828f | 2009-12-16 04:26:25 +0000 | [diff] [blame] | 40 | /* Log levels not defined for FW */ |
| 41 | #define LOG_SEV_TRACE 5 |
| 42 | #define LOG_SEV_DUMP 6 |
| 43 | |
| 44 | #define LOG_SEV_FW_FILTER_ALL \ |
| 45 | (BIT(LOG_SEV_CRITICAL) | \ |
| 46 | BIT(LOG_SEV_ERROR) | \ |
| 47 | BIT(LOG_SEV_WARNING) | \ |
| 48 | BIT(LOG_SEV_INFO) | \ |
Tomas Winkler | ab69a5a | 2009-10-17 09:09:34 +0000 | [diff] [blame] | 49 | BIT(LOG_SEV_INFOEX)) |
| 50 | |
Tomas Winkler | 0df828f | 2009-12-16 04:26:25 +0000 | [diff] [blame] | 51 | #define LOG_SEV_FILTER_ALL \ |
| 52 | (BIT(LOG_SEV_CRITICAL) | \ |
| 53 | BIT(LOG_SEV_ERROR) | \ |
| 54 | BIT(LOG_SEV_WARNING) | \ |
| 55 | BIT(LOG_SEV_INFO) | \ |
| 56 | BIT(LOG_SEV_INFOEX) | \ |
| 57 | BIT(LOG_SEV_TRACE) | \ |
| 58 | BIT(LOG_SEV_DUMP)) |
| 59 | |
Tomas Winkler | ab69a5a | 2009-10-17 09:09:34 +0000 | [diff] [blame] | 60 | /* log source */ |
| 61 | #define LOG_SRC_INIT 0 |
| 62 | #define LOG_SRC_DEBUGFS 1 |
| 63 | #define LOG_SRC_FW_DOWNLOAD 2 |
| 64 | #define LOG_SRC_FW_MSG 3 |
| 65 | #define LOG_SRC_TST 4 |
| 66 | #define LOG_SRC_IRQ 5 |
| 67 | |
| 68 | #define LOG_SRC_MAX 6 |
| 69 | #define LOG_SRC_ALL 0xFF |
| 70 | |
| 71 | /** |
| 72 | * Default intitialization runtime log level |
| 73 | */ |
| 74 | #ifndef LOG_SEV_FILTER_RUNTIME |
| 75 | #define LOG_SEV_FILTER_RUNTIME \ |
| 76 | (BIT(LOG_SEV_CRITICAL) | \ |
| 77 | BIT(LOG_SEV_ERROR) | \ |
| 78 | BIT(LOG_SEV_WARNING)) |
| 79 | #endif |
| 80 | |
| 81 | #ifndef FW_LOG_SEV_FILTER_RUNTIME |
| 82 | #define FW_LOG_SEV_FILTER_RUNTIME LOG_SEV_FILTER_ALL |
| 83 | #endif |
| 84 | |
| 85 | #ifdef CONFIG_IWMC3200TOP_DEBUG |
| 86 | /** |
| 87 | * Log macros |
| 88 | */ |
| 89 | |
| 90 | #define priv2dev(priv) (&(priv->func)->dev) |
| 91 | |
| 92 | #define LOG_CRITICAL(priv, src, fmt, args...) \ |
| 93 | do { \ |
| 94 | if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_CRITICAL)) \ |
| 95 | dev_crit(priv2dev(priv), "%s %d: " fmt, \ |
| 96 | __func__, __LINE__, ##args); \ |
| 97 | } while (0) |
| 98 | |
| 99 | #define LOG_ERROR(priv, src, fmt, args...) \ |
| 100 | do { \ |
| 101 | if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_ERROR)) \ |
| 102 | dev_err(priv2dev(priv), "%s %d: " fmt, \ |
| 103 | __func__, __LINE__, ##args); \ |
| 104 | } while (0) |
| 105 | |
| 106 | #define LOG_WARNING(priv, src, fmt, args...) \ |
| 107 | do { \ |
| 108 | if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_WARNING)) \ |
| 109 | dev_warn(priv2dev(priv), "%s %d: " fmt, \ |
| 110 | __func__, __LINE__, ##args); \ |
| 111 | } while (0) |
| 112 | |
| 113 | #define LOG_INFO(priv, src, fmt, args...) \ |
| 114 | do { \ |
| 115 | if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_INFO)) \ |
| 116 | dev_info(priv2dev(priv), "%s %d: " fmt, \ |
| 117 | __func__, __LINE__, ##args); \ |
| 118 | } while (0) |
| 119 | |
Tomas Winkler | 0df828f | 2009-12-16 04:26:25 +0000 | [diff] [blame] | 120 | #define LOG_TRACE(priv, src, fmt, args...) \ |
Tomas Winkler | ab69a5a | 2009-10-17 09:09:34 +0000 | [diff] [blame] | 121 | do { \ |
Tomas Winkler | 0df828f | 2009-12-16 04:26:25 +0000 | [diff] [blame] | 122 | if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_TRACE)) \ |
Tomas Winkler | ab69a5a | 2009-10-17 09:09:34 +0000 | [diff] [blame] | 123 | dev_dbg(priv2dev(priv), "%s %d: " fmt, \ |
| 124 | __func__, __LINE__, ##args); \ |
| 125 | } while (0) |
| 126 | |
| 127 | #define LOG_HEXDUMP(src, ptr, len) \ |
| 128 | do { \ |
Tomas Winkler | 0df828f | 2009-12-16 04:26:25 +0000 | [diff] [blame] | 129 | if (iwmct_logdefs[LOG_SRC_ ## src] & BIT(LOG_SEV_DUMP)) \ |
Tomas Winkler | ab69a5a | 2009-10-17 09:09:34 +0000 | [diff] [blame] | 130 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_NONE, \ |
| 131 | 16, 1, ptr, len, false); \ |
| 132 | } while (0) |
| 133 | |
| 134 | void iwmct_log_top_message(struct iwmct_priv *priv, u8 *buf, int len); |
| 135 | |
| 136 | extern u8 iwmct_logdefs[]; |
| 137 | |
| 138 | int iwmct_log_set_filter(u8 src, u8 logmask); |
| 139 | int iwmct_log_set_fw_filter(u8 src, u8 logmask); |
| 140 | |
| 141 | ssize_t show_iwmct_log_level(struct device *d, |
| 142 | struct device_attribute *attr, char *buf); |
| 143 | ssize_t store_iwmct_log_level(struct device *d, |
| 144 | struct device_attribute *attr, |
| 145 | const char *buf, size_t count); |
| 146 | ssize_t show_iwmct_log_level_fw(struct device *d, |
| 147 | struct device_attribute *attr, char *buf); |
| 148 | ssize_t store_iwmct_log_level_fw(struct device *d, |
| 149 | struct device_attribute *attr, |
| 150 | const char *buf, size_t count); |
| 151 | |
| 152 | #else |
| 153 | |
| 154 | #define LOG_CRITICAL(priv, src, fmt, args...) |
| 155 | #define LOG_ERROR(priv, src, fmt, args...) |
| 156 | #define LOG_WARNING(priv, src, fmt, args...) |
| 157 | #define LOG_INFO(priv, src, fmt, args...) |
Tomas Winkler | 0df828f | 2009-12-16 04:26:25 +0000 | [diff] [blame] | 158 | #define LOG_TRACE(priv, src, fmt, args...) |
Tomas Winkler | ab69a5a | 2009-10-17 09:09:34 +0000 | [diff] [blame] | 159 | #define LOG_HEXDUMP(src, ptr, len) |
| 160 | |
| 161 | static inline void iwmct_log_top_message(struct iwmct_priv *priv, |
| 162 | u8 *buf, int len) {} |
| 163 | static inline int iwmct_log_set_filter(u8 src, u8 logmask) { return 0; } |
| 164 | static inline int iwmct_log_set_fw_filter(u8 src, u8 logmask) { return 0; } |
| 165 | |
| 166 | #endif /* CONFIG_IWMC3200TOP_DEBUG */ |
| 167 | |
| 168 | int log_get_filter_str(char *buf, int size); |
| 169 | int log_get_fw_filter_str(char *buf, int size); |
| 170 | |
| 171 | #endif /* __LOG_H__ */ |