aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTom Rini2020-10-11 15:22:05 -0400
committerTom Rini2020-10-11 15:22:05 -0400
commit726561a9412abe50875b7791feab94f411d76199 (patch)
tree62196ca628174d0b1502fc0b87f09e7c73ce2e14 /include
parent0437cc415517c06c864bee5dbce3001d70b2c2cb (diff)
parent1ecb6beb95fcf3369bcd964f25d8954d048846a7 (diff)
Merge branch '2020-10-10-log-improvements'
- Assorted improvements to our log functionality.
Diffstat (limited to 'include')
-rw-r--r--include/log.h46
-rw-r--r--include/net.h2
2 files changed, 42 insertions, 6 deletions
diff --git a/include/log.h b/include/log.h
index 2859ce1f2e7..4acc087b2e9 100644
--- a/include/log.h
+++ b/include/log.h
@@ -33,6 +33,9 @@ enum log_level_t {
LOGL_COUNT,
LOGL_NONE,
+ LOGL_LEVEL_MASK = 0xf, /* Mask for valid log levels */
+ LOGL_FORCE_DEBUG = 0x10, /* Mask to force output due to LOG_DEBUG */
+
LOGL_FIRST = LOGL_EMERG,
LOGL_MAX = LOGL_DEBUG_IO,
};
@@ -133,7 +136,7 @@ static inline int _log_nop(enum log_category_t cat, enum log_level_t level,
#if CONFIG_IS_ENABLED(LOG)
#ifdef LOG_DEBUG
-#define _LOG_DEBUG 1
+#define _LOG_DEBUG LOGL_FORCE_DEBUG
#else
#define _LOG_DEBUG 0
#endif
@@ -141,9 +144,11 @@ static inline int _log_nop(enum log_category_t cat, enum log_level_t level,
/* Emit a log record if the level is less that the maximum */
#define log(_cat, _level, _fmt, _args...) ({ \
int _l = _level; \
- if (CONFIG_IS_ENABLED(LOG) && (_l <= _LOG_MAX_LEVEL || _LOG_DEBUG)) \
- _log((enum log_category_t)(_cat), _l, __FILE__, __LINE__, \
- __func__, \
+ if (CONFIG_IS_ENABLED(LOG) && \
+ (_LOG_DEBUG != 0 || _l <= _LOG_MAX_LEVEL)) \
+ _log((enum log_category_t)(_cat), \
+ (enum log_level_t)(_l | _LOG_DEBUG), __FILE__, \
+ __LINE__, __func__, \
pr_fmt(_fmt), ##_args); \
})
#else
@@ -279,8 +284,12 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line,
* Memebers marked as 'allocated' are allocated (e.g. via strdup()) by the log
* system.
*
+ * TODO(sjg@chromium.org): Compress this struct down a bit to reduce space, e.g.
+ * a single u32 for cat, level, line and force_debug
+ *
* @cat: Category, representing a uclass or part of U-Boot
* @level: Severity level, less severe is higher
+ * @force_debug: Force output of debug
* @file: Name of file where the log record was generated (not allocated)
* @line: Line number where the log record was generated
* @func: Function where the log record was generated (not allocated)
@@ -289,6 +298,7 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line,
struct log_rec {
enum log_category_t cat;
enum log_level_t level;
+ bool force_debug;
const char *file;
int line;
const char *func;
@@ -297,10 +307,16 @@ struct log_rec {
struct log_device;
+enum log_device_flags {
+ LOGDF_ENABLE = BIT(0), /* Device is enabled */
+};
+
/**
* struct log_driver - a driver which accepts and processes log records
*
* @name: Name of driver
+ * @emit: Method to call to emit a log record via this device
+ * @flags: Initial value for flags (use LOGDF_ENABLE to enable on start-up)
*/
struct log_driver {
const char *name;
@@ -311,6 +327,7 @@ struct log_driver {
* for processing. The filter is checked before calling this function.
*/
int (*emit)(struct log_device *ldev, struct log_rec *rec);
+ unsigned short flags;
};
/**
@@ -323,12 +340,14 @@ struct log_driver {
* @next_filter_num: Seqence number of next filter filter added (0=no filters
* yet). This increments with each new filter on the device, but never
* decrements
+ * @flags: Flags for this filter (enum log_device_flags)
* @drv: Pointer to driver for this device
* @filter_head: List of filters for this device
* @sibling_node: Next device in the list of all devices
*/
struct log_device {
- int next_filter_num;
+ unsigned short next_filter_num;
+ unsigned short flags;
struct log_driver *drv;
struct list_head filter_head;
struct list_head sibling_node;
@@ -369,6 +388,10 @@ struct log_filter {
#define LOG_DRIVER(_name) \
ll_entry_declare(struct log_driver, _name, log_driver)
+/* Get a pointer to a given driver */
+#define LOG_GET_DRIVER(__name) \
+ ll_entry_get(struct log_driver, __name, log_driver)
+
/**
* log_get_cat_name() - Get the name of a category
*
@@ -446,6 +469,19 @@ int log_add_filter(const char *drv_name, enum log_category_t cat_list[],
*/
int log_remove_filter(const char *drv_name, int filter_num);
+/**
+ * log_device_set_enable() - Enable or disable a log device
+ *
+ * Devices are referenced by their driver, so use LOG_GET_DRIVER(name) to pass
+ * the driver to this function. For example if the driver is declared with
+ * LOG_DRIVER(wibble) then pass LOG_GET_DRIVER(wibble) here.
+ *
+ * @drv: Driver of device to enable
+ * @enable: true to enable, false to disable
+ * @return 0 if OK, -ENOENT if the driver was not found
+ */
+int log_device_set_enable(struct log_driver *drv, bool enable);
+
#if CONFIG_IS_ENABLED(LOG)
/**
* log_init() - Set up the log system ready for use
diff --git a/include/net.h b/include/net.h
index 219107194f7..778acf7da3f 100644
--- a/include/net.h
+++ b/include/net.h
@@ -593,7 +593,7 @@ extern int net_ntp_time_offset; /* offset time from UTC */
#endif
/* Initialize the network adapter */
-void net_init(void);
+int net_init(void);
int net_loop(enum proto_t);
/* Load failed. Start again. */