diff options
author | Marcin Wojtas <mw@FreeBSD.org> | 2021-06-24 13:48:26 +0000 |
---|---|---|
committer | Marcin Wojtas <mw@FreeBSD.org> | 2021-06-24 13:48:26 +0000 |
commit | 1f4f67f52424ac53d07ff524af9762fdf2e2b210 (patch) | |
tree | 89964545fb49dc9f8d97c45bb8c972c4a0ded179 | |
parent | e0f5dd7cdd3d85acef2ecde7b74a952521e2e947 (diff) |
ena-com: restructure the ENA logging systemvendor/ena-com/2.4.0
Introduce a new logging system, which replaces the old logging method.
All logs are now displayed in `device_printf` format, requiring
`adapter->pdev` to be passed down to `ena_log`. Whenever that's
impossible, a `printf` wrapped `ena_log_raw` is provided.
For netmap logs, `ena_log_nm` is available, prepending "[nm] " to
an `ena_log` formatted message.
Tx/Rx data path logs are now printed via `ena_log_io`. This allows them
to be conditionally compiled out, depending on the presence of
ENA_LOG_IO_ENABLE compilation flag. By default this flag is disabled.
All `ena_trc_*` ena_com level messages are now also wrapped around
`ena_log` and require `ena_dev->dmadev` to be present.
There are four log levels:
* 0 - ENA_ERR - enable driver error messages and ena_com error logs,
* 1 - ENA_WARN - enable logs for non-critical errors,
* 2 - ENA_INFO - make the driver more verbose about its actions,
* 3 - ENA_DBG - enable debug logs
Please see `ena_fbsd_log.h` for implementation details.
Submitted by: Artur Rojek <ar@semihalf.com>
Obtained from: Semihalf
MFC after: 2 weeks
Sponsored by: Amazon, Inc.
-rw-r--r-- | ena_fbsd_log.h | 74 | ||||
-rw-r--r-- | ena_plat.h | 34 |
2 files changed, 81 insertions, 27 deletions
diff --git a/ena_fbsd_log.h b/ena_fbsd_log.h new file mode 100644 index 000000000000..311e2f0f280a --- /dev/null +++ b/ena_fbsd_log.h @@ -0,0 +1,74 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 2015-2021 Amazon.com, Inc. or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef ENA_FBSD_LOG_H +#define ENA_FBSD_LOG_H + +enum ena_log_t { + ENA_ERR = 0, + ENA_WARN, + ENA_INFO, + ENA_DBG, +}; + +extern int ena_log_level; + +#define ena_log(dev, level, fmt, args...) \ + do { \ + if (ENA_ ## level <= ena_log_level) \ + device_printf((dev), fmt, ##args); \ + } while (0) + +#define ena_log_raw(level, fmt, args...) \ + do { \ + if (ENA_ ## level <= ena_log_level) \ + printf(fmt, ##args); \ + } while (0) + +#define ena_log_unused(dev, level, fmt, args...) \ + do { \ + (void)(dev); \ + } while (0) + +#ifdef ENA_LOG_IO_ENABLE +#define ena_log_io(dev, level, fmt, args...) \ + ena_log((dev), level, fmt, ##args) +#else +#define ena_log_io(dev, level, fmt, args...) \ + ena_log_unused((dev), level, fmt, ##args) +#endif + +#define ena_log_nm(dev, level, fmt, args...) \ + ena_log((dev), level, "[nm] " fmt, ##args) + +#endif /* !(ENA_FBSD_LOG_H) */ diff --git a/ena_plat.h b/ena_plat.h index 9f4ceae24a41..b31821248398 100644 --- a/ena_plat.h +++ b/ena_plat.h @@ -91,20 +91,9 @@ __FBSDID("$FreeBSD$"); #include <dev/pci/pcivar.h> #include <dev/pci/pcireg.h> -extern struct ena_bus_space ebs; +#include "ena_fbsd_log.h" -/* Levels */ -#define ENA_ALERT (1 << 0) /* Alerts are providing more error info. */ -#define ENA_WARNING (1 << 1) /* Driver output is more error sensitive. */ -#define ENA_INFO (1 << 2) /* Provides additional driver info. */ -#define ENA_DBG (1 << 3) /* Driver output for debugging. */ -/* Detailed info that will be printed with ENA_INFO or ENA_DEBUG flag. */ -#define ENA_TXPTH (1 << 4) /* Allows TX path tracing. */ -#define ENA_RXPTH (1 << 5) /* Allows RX path tracing. */ -#define ENA_RSC (1 << 6) /* Goes with TXPTH or RXPTH, free/alloc res. */ -#define ENA_IOQ (1 << 7) /* Detailed info about IO queues. */ -#define ENA_ADMQ (1 << 8) /* Detailed info about admin queue. */ -#define ENA_NETMAP (1 << 9) /* Detailed info about netmap. */ +extern struct ena_bus_space ebs; #define DEFAULT_ALLOC_ALIGNMENT 8 #define ENA_CDESC_RING_SIZE_ALIGNMENT (1 << 12) /* 4K */ @@ -117,27 +106,18 @@ extern int ena_log_level; (type *)((uintptr_t)__p - offsetof(type, member)); \ }) -#define ena_trace_raw(ctx, level, fmt, args...) \ - do { \ - ((void)(ctx)); \ - if (((level) & ena_log_level) != (level)) \ - break; \ - printf(fmt, ##args); \ - } while (0) - #define ena_trace(ctx, level, fmt, args...) \ - ena_trace_raw(ctx, level, "%s() [TID:%d]: " \ + ena_log((ctx)->dmadev, level, "%s() [TID:%d]: " \ fmt, __func__, curthread->td_tid, ##args) - #define ena_trc_dbg(ctx, format, arg...) \ - ena_trace(ctx, ENA_DBG, format, ##arg) + ena_trace(ctx, DBG, format, ##arg) #define ena_trc_info(ctx, format, arg...) \ - ena_trace(ctx, ENA_INFO, format, ##arg) + ena_trace(ctx, INFO, format, ##arg) #define ena_trc_warn(ctx, format, arg...) \ - ena_trace(ctx, ENA_WARNING, format, ##arg) + ena_trace(ctx, WARN, format, ##arg) #define ena_trc_err(ctx, format, arg...) \ - ena_trace(ctx, ENA_ALERT, format, ##arg) + ena_trace(ctx, ERR, format, ##arg) #define unlikely(x) __predict_false(!!(x)) #define likely(x) __predict_true(!!(x)) |